>>>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)
, RIGHT('000' + cast(3333 as varchar(3)) ,3)
SELECT RIGHT('000' + cast(3333 as nvarchar(3)),3)