1

i have a table like

[A]-----------[B]
[0]-----------[0.012345]
[1]-----------[0.002345]
[0.2145]----[0.1457]

I need both columns A and B to be padded with zeros at the end upto 9th place after decimal so the output should look like:

[A]--------------------[B]
[0.000000000]-----------[0.012345000]
[1.000000000]-----------[0.002345670]
[0.214500000]-----------[0.145700000]

NOte: total number of digits = 10 not including '.'decimal

1
  • 1
    What are the column types? Commented Jan 29, 2014 at 23:54

1 Answer 1

2

Test Data

DECLARE @TABLE TABLE([A] VARCHAR(20),[B] VARCHAR(20))
INSERT INTO @TABLE VALUES
('0','0.012345'),('1','0.002345'),('0.2145','0.1457')

All you need to do is cast these values as DECIMAL(10,9) for more information about Decimal data type Read here

Query

SELECT CAST([A] AS DECIMAL(10,9)) AS A
      ,CAST([B] AS DECIMAL(10,9)) AS B
FROM @TABLE

Result Set

╔═════════════╦═════════════╗
║      A      ║      B      ║
╠═════════════╬═════════════╣
║ 0.000000000 ║ 0.012345000 ║
║ 1.000000000 ║ 0.002345000 ║
║ 0.214500000 ║ 0.145700000 ║
╚═════════════╩═════════════╝
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.