Groups | Blog | Home
all groups > sql server new users > november 2005 >

sql server new users : Help with Len



Arturo Iñiguez
11/15/2005 2:17:03 PM
Hi Group

I interest count the characters in the field (string), because, the result i
need whit 2 characters i.e.

ALCOCER = 7
I need
ALCOCER = 07
If the name is has more than 10 characters.

Roy Harvey
11/15/2005 8:59:52 PM
Arturo,

The DATALENGTH() function will return the length of a string.

Adding leading zeroes to a number is a different problem. Suppose you
need a number to be three characters long, with leading zeroes:

REPLACE(STR(Nbr,3), ' ', '0')

Or if you have a string, rather than a number:

RIGHT('000' + StringColumn, 3)

I hope this helps.

Roy



[quoted text, click to view]
AddThis Social Bookmark Button