Larry Brister
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
I mUST include decimal point
so
520.25
Must output as
00000520.2500
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
DECLARE @decimal decimal(16, 4)
SET @decimal = 520.25
SELECT REPLACE(STR(520.25, 13 , 4 ), ' ', '0')
SET @decimal = 520.25
SELECT REPLACE(STR(520.25, 13 , 4 ), ' ', '0')
ASKER
As always...thanks.
I prefer actual code to a link and usually take the first "best"
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.
Thx for letting me know; to help you out, I won't waste your time by posting my "secondary" answers to your future qs.
ASKER
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.
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.
http://raresql.com/2012/10/09/sql-server-200520082012-leading-zero-to-number/