Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi I'm extracting a char(2) field from a table that has a value of '1' and writing it to another table but want the output field to be padded with a zero. I have tried this below: right('00' + isnull(Field1, ' '),2but the output field comes out as '1 ' (that's 1 followed by a space). Does anyone have any idea how I can do this or please point out what I'm doing wrong in my 'right(' fucntion above.Thanks,Jeff
nr
SQLTeam MVY
12543 Posts
Posted - 2006-04-06 : 13:12:23
right('00' + isnull(rtrim(Field1), ''),2)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2006-04-06 : 13:14:46
Your value of 1 is padded since you are using char. Check this out:
declare @s char(2)set @s = '1'if @s = '1 ' print 'padded with a space'else print 'unpadded'