Re: How can I conserve the initial zero when convert numeric to string using STR()
- From: "Mike C#" <xxx@xxxxxxx>
- Date: Sun, 28 May 2006 00:06:45 -0400
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@xxxxxxxxx> wrote in message
news:1148779910.070643.296910@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.
.
- References:
- Prev by Date: T-SQL CLOSE Connection to DB
- Next by Date: Re: Insert a record in a particular place
- Previous by thread: How can I conserve the initial zero when convert numeric to string using STR()
- Next by thread: Re: How can I conserve the initial zero when convert numeric to string using STR()
- Index(es):
Relevant Pages
|