x
Solved

# add 0 value on select

Posted on 2010-11-22
Medium Priority
336 Views
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
Question by:Seven price

LVL 143

Accepted Solution

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

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

ID: 34188646
thanks
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Join & Write a Comment Already a member? Login.

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
###### Suggested Courses
Course of the Month7 days, 16 hours left to enroll

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

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