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 |
|
mzmatterafact
Starting Member
6 Posts |
Posted - 2008-07-24 : 12:50:34
|
| I have an sql statement where I am using the DATEDIFF function to return a number of days, which returns the result as an Integer. I need to from 0-997. I need to display that result so when the number is 0 it shows as 000, etc. I have some 1's to display as 001 or 87 should display as 087. I've tried so many things that didn't work, I hope i can find an answer here! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-24 : 12:54:57
|
| right('000'+CAST(DATEDIFF(...) AS varchar(3)),3) |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-07-24 : 13:23:35
|
| Where and how are you outputting your results? It is almost always much easier, quicker, and a better practice overall to simply format raw data at the presentation layer rather than to try to convert all of your data to VARCHAR strings using convoluted expressions in T-SQL.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
mzmatterafact
Starting Member
6 Posts |
Posted - 2008-07-24 : 14:59:53
|
quote: Originally posted by visakh16 right('000'+CAST(DATEDIFF(...) AS varchar(3)),3)
Thanks, this helped perfectly!! |
 |
|
|
|
|
|