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 2008 Forums
 Transact-SQL (2008)
 SQL Help

Author  Topic 

accessdbguru
Starting Member

26 Posts

Posted - 2012-08-13 : 12:47:59
I need help in writing an SQL to pull check amount and check number to contain 14 digits starting with 0.

Example if amount is
14.35 should display as 000000000014.35

Example if check number is
56345 should display as 00000000056345

Thank you for your help.

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-08-13 : 14:11:06
declare @accessguru table(somecolumn varchar(max))
insert into @accessguru
select '14.35'
union
select '56345'

select *, REPLACE(CAST(POWER(10, 14 - LEN(somecolumn) ) as varchar(max)), '1','') + somecolumn as xoxo, LEN(somecolumn) From @accessguru


<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-13 : 14:14:39
[code]
SELECT RIGHT('00000000000000' + CAST(numberfield AS varchar(15)),CASE WHEN CHARINDEX('.',numberfield) > 0 THEN 15 ELSE 14 END) FROM table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -