Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Concat

Author  Topic 

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-04-19 : 00:12:31
Hi peso, hi KH, Hi everyone....

Declare @day int
set @day = 3

select right('0' + @day, 2)

My expected result is : 03
If single integer - will append in the right a '0'.
If 2 digit integer - will return the actual value.

Thanks.

-Ron-

"If you can only access one site on the Internet, make it SQLTeam!"

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-04-19 : 00:20:09
change your select to:

select right('00' + convert(varchar,@day), 2)


www.elsasoft.org
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-19 : 00:24:53
arrgh . . . too late.


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-04-19 : 00:28:00
quote:
select right('0' + @day, 2)

for this "'0' + @day", SQL Server will convert the string '0' to integer first before adding.
So it will be 0 + 2 = 2 then 2 convert to string


KH

Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-04-19 : 01:34:23
quote:
Posted - 04/19/2007 : 00:24:53
--------------------------------------------------------------------------------
arrgh . . . too late.


--------------------------------------------------------------------------------
KH




-Ron-

"If you can only access one site on the Internet, make it SQLTeam!"
Go to Top of Page
   

- Advertisement -