all groups > sql server programming > july 2006 >
You're in the

sql server programming

group:

alternative function for to_char in sql server


alternative function for to_char in sql server JP
7/2/2006 10:38:02 PM
sql server programming: Hi,

Is there any alternative function for to_char in sql server 2005(T-SQL) that
converts numeric to character in the specified format?

to_char(5,'09')
will result in 05 (in oracle)

to_char(10,'09')
will result in 10 (in oracle)

Thanks
RE: alternative function for to_char in sql server Omnibuzz
7/2/2006 11:04:02 PM
You dn't have a direct function.
Maybe you can use something like this

declare @a int ,@no_of_digits int

set @a = 10 -- value
set @no_of_digits = 2 -- No of digits you want to have in the final string

select right(replicate('0',@no_of_digits) + cast(@a as
varchar(30)),@no_of_digits)


Hope this helps.
--
-Omnibuzz (The SQL GC)

http://omnibuzz-sql.blogspot.com/

Re: alternative function for to_char in sql server Uri Dimant
7/3/2006 8:57:12 AM
JP
No, there isn't

DECLARE @c AS INT
SET @c=9

SELECT CASE WHEN LEN(@c)=1 THEN '0'+ CAST(@c AS VARCHAR(2))
ELSE CAST(@c AS VARCHAR(2)) END




[quoted text, click to view]

AddThis Social Bookmark Button