| Posted by Mike C# on 05/28/06 07:06 
You can't "preserve" the zero.  Integer 06 = Integer 6 = Integer 00000000006.
 
 If you want to convert an integer to a varchar you can prepend a 0 character
 to the result:
 
 SELECT '0' + CAST(06 AS VARCHAR)
 
 Returns '06'.  The downside to this method is that if you do something like
 
 SELECT '0' + CAST(10 AS VARCHAR)
 
 You'll end up with '010' which may or may not be what you want.  You can
 build on this example with the SUBSTRING function to get exactly what you
 really want out of it.
 
 <angellian@gmail.com> wrote in message
 news:1148779910.070643.296910@g10g2000cwb.googlegroups.com...
 > Sorry to raise a stupid question but I tried many methods which did
 > work.
 > how can I conserve the initial zero when I try to convert STR(06) into
 > string in SQL statment?
 > It always gives me 6 instead of 06.
 >
 > Thanks a lot.
 >
  Navigation: [Reply to this message] |