As long as you're not inserting the value into a numeric field this should display just fine.
Main Topics
Browse All TopicsHI Guys, I have a question. I have to output 2 implied decimal amount fields (AJ_Dollar_Amount & AJ_Amount). I have defined they as decimal (13, 0) and decimal (17, 0) respectively. I was told to use the following func to pad the field, but it is not working. How should I define field(s) or rewrite the Cast statement to get it to work?
Right('0000000000000' + Cast(AJ_Dollar_Amt as varchar (13)), 13),
Thank you,
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
For some reason I'm not getting the padding. I have a field Dollar_Amount there are 3 recs that have a dollar amount value. The amounts are 250, 200, 1125. i have a second field that is a sum of Dollar_Amount named Total_Amount. The values are displaying as 250, 200 and 1125, and the Total is displaying as 1575. I want them to display as 0000000000250, 0000000000200, 0000000001125 and 00000000000001575.
They are defined as:
Dollar_Amt (decimal (13, 0), null)
Total_Amount (decimal (17,0), null)
DECLARE @Cnt int;
DECLARE @Amt int;
BEGIN -- HDAJ ACSB 022208 082815 6 Byte date(mmddyy) 6 byte time (hhmss) 2 seperate fields
INSERT INTO dbo.tbl_Output (Record_Code, Institution, hdrDate, hdrTime)
Values ('HDAJ','ACSB', replace(CONVERT(CHAR(8), getdate(), 10), '-', ''),
replace(CONVERT(CHAR(8), GETDATE(), 108), ':', ''))
INSERT INTO dbo.tbl_Output (Record_Code, AJ_Batch_Type, AJ_Batch_Code,
AJ_Batch_Num, AccountNumber, AJ_Tran_Code, Merchant_No, AJ_Dollar_Amt, Reason_Code, AJ_Merch_Descr, [Timestamp])
SELECT AJ_Record_Code, AJ_Batch_Type, AJ_Batch_Code, AJ_Batch_Num,
AccountNumber, AJ_Tran_Code, Merchant_No,
Right('0000000000000' + Cast(AJ_Amount as varchar (13)), 13),
Reason_Code, AJ_Merch_Descr, [Timestamp]
FROM dbo.tblArchive
SET @Cnt = (SELECT Count(AJ_Record_Code) FROM dbo.tblArchive GROUP by AJ_Record_Code) + 2
SET @Amt = (SELECT Sum(AJ_Amount) FROM dbo.tblArchive GROUP by AJ_Record_Code)
INSERT INTO dbo.tbl_Output
(Record_Code,
Institution,
Record_Count,
Adj_Amount)
SELECT 'TLAJ','ACSB', Right('00000' + Cast(@Cnt as varchar (5)), 5),
Right('00000000000000000' + Cast(@Amt as varchar (17)), 17)
END
END
Angel1111 thanks for responding so quickly.
Adj_Amount int, it was nvarchar but I changed it when that didn't work. My values are 200,, 250, 1125 and 1575 (whch is the sum of the first three values)
I want 0000000000200; 0000000000250; 0000000001125
00000000000001575
The entire field s/b padded with zeros or numeric value.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2008-03-08 at 12:38:09ID: 21078535
the function shall be working.
what is "wrong"?