473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Adding leading zero's (padding out)

7
Good Afternoon

I need a column to show in a report as 10 digits long by adding zero's to the left of the result. My select statement is like this:

SELECT
a.client,
a.apar_id

FROM agltransact a
where a.client = 'SD'
and a.account NOT IN ('9600','9621')
and a.dim_2 <> ''
and a.voucher_type = 'AP'

my result is:

client apar_id
SD 2097
SD 2013
SD 20026
SD 2531
SD 2472
SD 2085

What I need is the apar_id column to be 10 digits long, preceeded with leading zero's. The results could have as little as 3, or as many as 7 digits.Can anyone help me out with the sql to show this? I am using ms sql server. The column I believe is a varchar.

Many Thanks

Lorna
Oct 5 '09 #1
1 7932
ck9663
2,878 Expert 2GB
Convert it, then pad it...

Expand|Select|Wrap|Line Numbers
  1.  
  2. right(replicate('0',10) + ltrim(cast(apar_id as varchar(10))),10)
  3.  
  4.  
Happy Coding!!!


--- CK
Oct 7 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Saiyan Vejita | last post by:
I am trying to add some padding to my table; that is, I want to add space between the red outer border and the content within. However, setting the "padding : 30px;" within the TABLE area of my...
15
by: Stormkid | last post by:
Hey Gang, I'm trying to figure out the best way to add two times together of the format hh:mm:ss any suggestions would be great thanks Todd
4
by: TJS | last post by:
I am populating a droplist control from a query. each line of content in the dropdownlist gets "trimmed" automatically . how can I force a leading space to a line in a dropdown list ??
3
by: David Stone | last post by:
I'm trying to apply a border to a Flash learning object, which is loaded into a page via <object>. I'm trying to use a style to put a black border around the Flash object. ...
4
by: comp.lang.php | last post by:
Could someone please spot-check this function and tell me why it never, ever, pads an integer with a leading zero when I want it to? This function fails in PHP 4.3.8, 4.4.1 and 4.3.9 Thanx...
5
by: GarryJones | last post by:
I have code numbers in 2 fields from a table which correspond to month and date. (Month, Code number) Field name = ml_mna 1 2 3 etc up to 12 (Data is entered without a leading zero)
8
by: Andrew Poulos | last post by:
In my limited testing with FF 2, IE 6 and Opera 9 when I divided a positive integer, that is less than 100, by 100 I get a leading zero in front of the decimal point. For example 80/100 gives...
1
by: Monte Cristo | last post by:
Hi all, I'm having a problem with results being returned from a data source, it's returning the right value but without the zero's "0" in front. I've searched through google for "padding zero's in...
4
by: Joe Cool | last post by:
I am trying to force a numericupdown control to display leading zeros. The maximum is less than 100, so the displayed value will always be a two digit number or less. So I have overridden the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.