Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Leading zeros

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2014-03-20 : 12:08:19
I have a decimal field that I am pulling into a view.

One record currently has 500 as a value.

I need to change this to 000000500.0000+

field name: Qty_rec

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-03-20 : 12:19:26
What is "000000500.0000+" is that a string?
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2014-03-20 : 13:01:55
Yes
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-03-20 : 13:47:24
I'm not sure why you'd want to do that, as it seems like a presentation issue to me. But, if you want to, here is one way:
DECLARE @Foo DECIMAL(18,5) = 500

SELECT RIGHT(REPLICATE('0', 9) + CAST(CAST(@Foo AS INTEGER) AS VARCHAR(20)), 9) + '.0000+'
Go to Top of Page
   

- Advertisement -