Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
LEFT justify and Replicate Spaces as required
Message
General information
Forum:
Microsoft SQL Server
Category:
Import/Export
Miscellaneous
Thread ID:
00998925
Message ID:
00998937
Views:
17
Sergey;

That worked like a charm! Thank you very much. This will resolve this issue which effects about a dozen fields. I have another question that I will post in a new message. If this keeps up I will hvae a great weekend! We have tomorrow off.

Tom

>Tom,
>
>Try
SELECT [NAME Code]
>     + CONVERT( char(30),  ISNULL(CONVERT(VARCHAR(30), [Scrap Reference Number]), ' '))
A couple of comments:
>- It's better always specify data size so you don't get bitten by defaults
>- I would use CAST() instead of CONVERT() because it's ANSI standard
>
CAST ( ISNULL( CAST([Scrap Reference Number] AS VARCHAR(30)), ' ') AS char(30))
>
>>I have to create several files to FTP to a UNIX machine. The layout of the data is column specific that is each column has a maximum length and position.
>>
>>I have a requirement to LEFT justify a number of fields in a Select Statement. I then have to Pad with Spaces to the required number of characters, in this case the maximum length is 30. The code below works as desired but RIGHT justifies the result.
>>
>>The code below represents a fragment of the Select statement to simplify the question.
>>
>>
>>SELECT [NAME Code]
>>     +SUBSTRING(REPLICATE(' ', 30-LEN(CONVERT(VARCHAR, [Scrap Reference Number])))
>  ISNULL(CONVERT(VARCHAR, [Scrap Reference Number]), ' '),1,30)
>>
Previous
Reply
Map
View

Click here to load this message in the networking platform