0

Need to sum(amounts) ,give it '0' padding of 10 character,replace the decimal with blank

eg:

Amount
34.56
45.12
12.23

Answer should look like 0000009191

+ cast((SELECT sum([amount]) from #clm2) as CHAR(10))

how can i do this?

2

2 Answers 2

1

If 2012+, consider Format()

Declare @Yourtable table (amount decimal(10,2))
Insert Into @Yourtable values
(34.56),
(45.12),
(12.23)

Select Format(sum(Amount*100),'0000000000')
 From  @YourTable

Returns

0000009191
Sign up to request clarification or add additional context in comments.

1 Comment

What do you mean with "2012+"? There is no such SQL standard
0

you can try this

for padding

select '0000000000' + cast(fieldname as varchar)

and replace dots with blank space with padding

select replace('0000000000' + cast(fieldname as varchar),'.','')

get 10 characters from right

select right(replace('0000000000' + cast(fieldname as varchar),'.',''),10)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.