Another MSSQL Question

GotIssues

Golden Member
Jan 31, 2003
1,631
0
76
Ok, another question from the MSSQL newb. I'm just getting my feet wet with the language, and have a major project that involves it, time is becoming an issue for me :(. I know of no better place to go, so please bare with me ;)

Ok, here is the dilemma. Taking a datatype for money in the format DDDDDDD.CC and I need it to convert to DDDDDDDCC, no decimal point and leading zeros where applicable.

Thanks for the help!
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
i dont think theres a built in way of doing this, this shoudl work for most cases:

select right(replicate('0',11) + replace(convert(nvarchar,<moneycol>),'.',''),9)

will pad left with 0's, remove the . and and return 9 right digits
 

KLin

Lifer
Feb 29, 2000
30,430
746
126
SELECT Replicate('0', 9-len(Cast(MoneyField*100 As Int))) + Cast(Cast(Moneyfield*100 As int) As varchar(9))