Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TSQL padleft
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01387814
Message ID:
01387844
Vues:
44
Bill,
SET with SELECT?
I don't know why I always hate such construction, why not just:
set @ReturnString = REPLICATE(@pcPadChar, @pnLength - DATALENGTH(@pcString)) + @pcString)
>>I need to padlef a string with zeros in TSQL, but I can't find the command.
>>42 -> 0042
>>
>>Any help would be appreciated.
>>
>>Thanks,
>>Einar
>
>For reference, here are TSQL function definitions for PADL and PADR..
>
>_______________________________________________
>
>create function PADL (@pcString varchar(200),@pnLength int,@pcPadChar char(1))
>returns varchar(200)
>
>as
>
>BEGIN
>
>declare @ReturnString varchar(200)
>
>if @pcString is NULL
> set @pcString = ''
>
>if datalength(@pcString)>@pnLength
>
> set @ReturnString = left(@pcString,@pnLength)
>
>else
>
> set @ReturnString = (SELECT REPLICATE(@pcPadChar, @pnLength - DATALENGTH(@pcString)) + @pcString)
>
>
>return @ReturnString
>
>END
>
>______________________________________________________
>
>
>create function PADR (@pcString varchar(200),@pnLength int,@pcPadChar char(1))
>returns varchar(200)
>
>as
>
>BEGIN
>
>declare @ReturnString varchar(200)
>
>if @pcString is NULL
> set @pcString = ''
>
>if datalength(@pcString) > @pnLength
>
> set @returnString = left(@pcString,@pnLength)
>
>else
>
> set @ReturnString = (SELECT @pcString + Replicate(@pcPadChar,@pnLength - datalength(@pcString)) )
>
>
>return @ReturnString
>
>END
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform