Connecting Tech Pros Worldwide Help | Site Map

Right Justified with leading zeroes

benchpolo's Avatar
Member
 
Join Date: Sep 2007
Location: Nevada
Posts: 92
#1: Jul 11 '08
ColumnName: issueamount (No Decimal Places)
Columnlength: 10
Data: 9999

How can I export the data of 9999 to a fixed length text (.txt) file with a leading zero infront like 0000009999?

left(IsNull(ltrim(rtrim( issueamount)),'')+ ' ',10)

Thanks.
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Jul 12 '08

re: Right Justified with leading zeroes


Modify your code to:

right(IsNull(ltrim(rtrim(cast(issueamount as varchar(5)))),'')+ '0',10)

-- CK
deepuv04's Avatar
Expert
 
Join Date: Nov 2007
Posts: 202
#3: Jul 15 '08

re: Right Justified with leading zeroes


Hi,
Try the following code

[code =sql]
SELECT REPLICATE('0', 10 - LEN(CAST(issueamount AS VARCHAR(10)))) + CAST(issueamount AS VARCHAR(10))

[/code]

Thanks
Reply


Similar Microsoft SQL Server bytes