Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Padding values in concatenated SELECT
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00514206
Message ID:
00514255
Views:
12
Evan,

You can very simply pad spaces to the right of a char field by casting it as the length as you want. Run the following SQL to see an example:
declare @field1 char(5)
,@field2 char(5)
,@field3 char(5)

SELECT @field1 = 'AAA'
SELECT @field2 = 'BBBBB'
SELECT @field3 = 'CC'

SELECT @field1 + @field2 + @field3 + 'D'
SELECT cast(@field1 AS char(10)) + cast(@field2 AS char(10)) + cast(@field3 AS char(10)) + 'D'
BOb


>Hi all,
>
>Is there in T-SQL an equivalent to the VFP PADL/PADC/PADR() functionality which pads a char value with spaces?
>
>REASON: I'd like to build a concatenated item in a SELECT statement, something like this:
>
>SELECT Field1 + Field2 + Field3 AS MyField
>
>but I need the first two fields to be a specific length that is DIFFERENT from the field length in the table (ie, with a couple of added spaces at the end). I know I can include a SPACE( x ) in the concatenation ... but I was hoping for an easier way (g).
>
>TIA.
Previous
Reply
Map
View

Click here to load this message in the networking platform