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 |
|
rjackman1959
Yak Posting Veteran
60 Posts |
Posted - 2009-01-18 : 18:31:44
|
| I am trying to count records and show the output as a 6 character output with leading zeros and no decimal. I though this would work, but it doesn’tstr(count(d.uprtrxam), 7, 0), I get “ 111”Then I need to to a 19,5 numeric field an select it giving a 17,2 output with leading zeros. I think I am allmost there, but not quite. Any help would be appriciated. Thank Youstr(sum(d.uprtrxam), 17, 2), I get “ 4383.97” |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2009-01-18 : 21:41:09
|
| It might pay to create a function for this so you can use it from anywhere.The psuedocode would be:- Convert the number to a string (using CONVERT if you like but it should implicitly convert)- Find the length of the new string- Create a string with the number of zeroes (required length-length of new string) and append the new string onto it.Hope this makes sense. |
 |
|
|
rjackman1959
Yak Posting Veteran
60 Posts |
Posted - 2009-01-18 : 21:57:24
|
| Thanks TimmyI am really new to SQL, but learning. Could you give a syntax example of the easiest one that would work? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-18 : 22:40:38
|
| something like right('0000000000000'+ cast(yourvalue as varchar(26)),19) |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-01-19 : 03:09:48
|
REPLACE(str(count(d.uprtrxam), 19, 2), ' ', '0') E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|
|
|