July 21, 2010 at 9:25 am
Hi All,
Could anyone help me with the code to convert Decimal(18,6) format into char(11) for an export. I need to get figures like 11.240000 to look like 00000001124.
Cheers
Matt
July 21, 2010 at 9:28 am
Sorry forgot to mention, the figures will vary so you may get 100.290000 or 1000.290000 which would need to look like 00000010029 and 00000100029
July 21, 2010 at 9:36 am
SELECT MyPrettyNumber = REPLACE(STR(MyNumber*100,11,0), ' ', '0')
FROM (
SELECT MyNumber = CAST(11.24 AS DECIMAL(18,6))
UNION ALL SELECT 100.290000
UNION ALL SELECT 1000.290000
) d
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 21, 2010 at 9:42 am
Thanks Chris, that worked a treat.
July 21, 2010 at 9:44 am
You're welcome Matt, thanks for the feedback.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply