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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Baffled - Right() function doesn't seem to work

Author  Topic 

gohanman
Starting Member

2 Posts

Posted - 2010-09-02 : 11:56:46
I'm trying trying to zero-pad an integer column to a set length. This seems like it should be easy, but the results I'm getting aren't useful and I'm not sure why.

QUERY:

select coupID,
'00000'+convert(char,coupID),
right('00000'+convert(char,coupID),5)
from houseCoupons


RESULT:

1,'000001',''


I don't get why the third column is blank. The function seems to recognize the first parameter as valid character data - there are no errors. But I'm not getting the right-hand 5 characters of the expression...

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-02 : 12:35:55
Use Varchar(10) instead of char

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

gohanman
Starting Member

2 Posts

Posted - 2010-09-02 : 12:49:56
Interesting. That makes it work, even without the length specification. Any idea why?

Regardless, thanks for the help.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-02 : 12:53:45
Read this
http://beyondrelational.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -