Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

add 0 value on select

Posted on 2010-11-22
3
Medium Priority
?
332 Views
Last Modified: 2012-05-10
i have a column that has quantity's in it but if my quantity  is a one digit then add 0 in front this works
example
5 below makes it 05 or 8 makes it 08 and it leaves it if it is 55 or 88.

right('0'+convert(varchar(3),DOD.Quantity),2)

But the problem if there is a 3 digit quantity and the  quantity for example is 323 it will only display 23, I do not want to increase the 0 because I do not want it to turn out 055 or 023.

I just need if one digit add 0 in front else more than one digit then do not add 0's
0
Comment
Question by:Seven price
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 34188625
select case when DOD.Quantity < 10 then '0' else '' end + cast(DOD.Quantity as varchar(20))
0
 
LVL 13

Expert Comment

by:Rick
ID: 34188641
IF value < 10 THEN
right('0'+convert(varchar(3),DOD.Quantity),2)
ELSE END as 'Column Name'
0
 
LVL 9

Author Closing Comment

by:Seven price
ID: 34188646
thanks
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question