Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Padding values in concatenated SELECT
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00514206
Message ID:
00514255
Vues:
13
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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform