Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Equivalent to PADL()?
Message
De
18/10/2012 09:14:46
 
 
À
18/10/2012 04:35:35
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01555196
Message ID:
01555237
Vues:
47
>>>>I'm "translating" an SQL statement from VFP and one of the fields I'm pulling needs to be nchar(3) left filled with '0'.
>>>>
>>>>In VFP it's PADL(alltrim(str(eclscore)),3,'0') - eclscore is a numeric, so I know I need to Cast(eclscore as nchar(3)), but I can't seem to find the PADL replacement - what should I be using to do the PADL?
>>>
>>>Try
>>>
>>>select RIGHT('000' + cast(EclScore as varchar(10)),3)
>>
>>Is there a specific reason you're casting as a varchar(10)? I'm asking for clarification, not to be a smart a$$.
>
>It depends on what you want to achieve if the number has more than 3 digits:
>
>select	RIGHT('000' + cast(3333 as varchar(10)),3)  -- 333
>	,	RIGHT('000' + cast(3333 as varchar(3)) ,3)   -- 00* 
>
>SELECT	RIGHT('000' + cast(3333 as nvarchar(3)),3) -- Error 8115
>
This field is a test score and ranges from 0-100, so I know that it will always be a max of 3 digits. Amazingly enough, I had to go with
Select Right('000 + cast(eclscore as nchar(3)),4)
to get the results I needed.
Select Right('000 + cast(eclscore as nchar(3)),3)
produced '68' from a score of 68. I got what I was expecting when I went to the 4 - '068' for 68.
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform