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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 money format pad left and right with zeros

Author  Topic 

mayerl
Yak Posting Veteran

95 Posts

Posted - 2010-07-02 : 12:18:24
Morning,

I have to send a text file in a specific format. For example 124 would have to be sent as 000124.0000.

I was using

select right('00000000000'+convert(varchar,'124'),11)unit_price


which gives me 00000000124

What is the best way to get this?

Thanks for any help.

Laura

mayerl
Yak Posting Veteran

95 Posts

Posted - 2010-07-02 : 12:20:13
Found it : RIGHT(REPLICATE('0', 11)+ CAST(CAST('124' AS NUMERIC(9,4)) AS VARCHAR) ,11)

Love it when I found my own answers....
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-07-02 : 12:58:43
There's also:

SELECT REPLACE(STR(124,11,4), ' ', '0')
Go to Top of Page
   

- Advertisement -