Link to home
Create AccountLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Select Fixed length output with leading zeroes and decimal

I need to output to a fixed length (13) column with leading and trailing zeroes.

I mUST include decimal point

so
520.25
Must output as
00000520.2500
Avatar of mimran18
mimran18
Flag of United Arab Emirates image

ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
DECLARE @decimal decimal(16, 4)

SET @decimal = 520.25

SELECT REPLACE(STR(520.25, 13 , 4 ), ' ', '0')
Avatar of Larry Brister

ASKER

As always...thanks.

I prefer actual code to a link and usually take the first "best"
You mean the first period, as long as it works, not the "best".

Thx for letting me know; to help you out, I won't waste your time by posting my "secondary" answers to your future qs.
ScottPletcher

Not being a dba or school trained I take what looks best to ME.

How would I know which is best if two appear to work fine to me (a layman)?

You've given me many answers in the past and I appreciate it...didn't mean to insult you.

Whether you post answers or not is entirely up to you.