Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Equivalent to PADL()?
Message
 
 
To
17/10/2012 16:03:48
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01555196
Message ID:
01555204
Views:
42
>>>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$$.

Sorry, is the field defined as nchar(3)? In this case we need to cast to nvarchar(3). We need to use varchar or nvarchar type, as char type is prepended with the spaces.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform