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.
| Author |
Topic |
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2005-04-19 : 08:06:01
|
| I'm now losing the plot. I was sure there was a function that does this but can't find itI want to convert a number into a padded (to n characters) character typeso for example (assuming I'm padding to 5 characters) then I should get1 -> 0000120 -> 000201234 -> 01234etc.Many thankssteveA sarcasm detector, what a great idea. |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-04-19 : 08:08:17
|
| SELECT RIGHT('0000'+convert(varchar(5),yourfield),5) from yourtableShould do it-------Moo. :) |
 |
|
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2005-04-20 : 02:48:24
|
| ThankssteveA sarcasm detector, what a great idea. |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2005-04-20 : 04:47:54
|
| also:declare @n intset @n=5select replicate('0',@n-len(data)) + data from tableX--------------------keeping it simple... |
 |
|
|
elwoos
Master Smack Fu Yak Hacker
2052 Posts |
Posted - 2005-04-21 : 03:14:26
|
| Cheers Jen, I've already implemented what Mr Mist suggested but when I get a moment I'll look at the execution plans for them boththankssteveA sarcasm detector, what a great idea. |
 |
|
|
|
|
|