Solved

add 0 value on select

Posted on 2010-11-22
3
314 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:sevensnake77
3 Comments
 
LVL 142

Accepted Solution

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

Expert Comment

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

Author Closing Comment

by:sevensnake77
Comment Utility
thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now