This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Solved

Posted on 2014-04-28

Hello:

Below is a T-SQL field that I programmed called "ytdhours".

As you can see, it needs to be a total of six digits--four to the left of the decimal place and two to the right.

But, I need leading zeroes to dynamically appear to the left of the decimal. For example, the result that was derived from running this was "429.75". I need the result to be "0429.75". Or, if the result had been "29.75", I would need it to actually be "0029.75".

How can I accomplish this?

Thanks!

TBSupport

CAST(SUM(MED.dbo.UPR30301.MTDHOURS_1 / CAST(100 AS DECIMAL(18, 2)))

+ SUM(MED.dbo.UPR30301.MTDHOURS_2 / CAST(100 AS DECIMAL(18, 2))) + SUM(MED.dbo.UPR30301.MTDHOURS_3 / CAST(100 AS DECIMAL(18, 2)))

+ SUM(MED.dbo.UPR30301.MTDHOURS_4 / CAST(100 AS DECIMAL(18, 2))) + SUM(MED.dbo.UPR30301.MTDHOURS_5 / CAST(100 AS DECIMAL(18, 2)))

+ SUM(MED.dbo.UPR30301.MTDHOURS_6 / CAST(100 AS DECIMAL(18, 2))) + SUM(MED.dbo.UPR30301.MTDHOURS_7 / CAST(100 AS DECIMAL(18, 2)))

+ SUM(MED.dbo.UPR30301.MTDHOURS_8 / CAST(100 AS DECIMAL(18, 2))) + SUM(MED.dbo.UPR30301.MTDHOURS_9 / CAST(100 AS DECIMAL(18, 2)))

+ SUM(MED.dbo.UPR30301.MTDHOURS_10 / CAST(100 AS DECIMAL(18, 2))) + SUM(MED.dbo.UPR30301.MTDHOURS_11 / CAST(100 AS DECIMAL(18, 2)))

+ SUM(MED.dbo.UPR30301.MTDHOURS_12 / CAST(100 AS DECIMAL(18, 2))) AS decimal(6, 2)) AS ytdhours

Below is a T-SQL field that I programmed called "ytdhours".

As you can see, it needs to be a total of six digits--four to the left of the decimal place and two to the right.

But, I need leading zeroes to dynamically appear to the left of the decimal. For example, the result that was derived from running this was "429.75". I need the result to be "0429.75". Or, if the result had been "29.75", I would need it to actually be "0029.75".

How can I accomplish this?

Thanks!

TBSupport

CAST(SUM(MED.dbo.UPR30301.

+ SUM(MED.dbo.UPR30301.MTDHO

+ SUM(MED.dbo.UPR30301.MTDHO

+ SUM(MED.dbo.UPR30301.MTDHO

+ SUM(MED.dbo.UPR30301.MTDHO

+ SUM(MED.dbo.UPR30301.MTDHO

+ SUM(MED.dbo.UPR30301.MTDHO

3 Comments

SELECT RIGHT('0000'+ CONVERT(VARCHAR, xxxx ),4)

Replacing the 'xxxx' with your query above.

Then you need to display it as a character value, as no numeric data types support leading zeros. Copy-paste the below T-SQL into your SSMS, execute it to verify it's what you need, then modify to meet your needs.

```
Declare @val numeric(7,2) = 429.75
SELECT RIGHT('0000000' + CAST(@val as varchar(7)), 7)
```

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Simple Linear Regression

Join the community of 500,000 technology professionals and ask your questions.