Afrah
Afrah

Reputation: 63

How to put a dot before last 2 numbers in SQL Server

I have column with numbers.

[375512] [122451] [0] [0] [152315] 

I would like to have these number with a dot before the last 2 numbers

[3755.12] [1224.51] [0.00] [0.00] [1523.15] 

I am using SQL Server 2012.

Upvotes: 3

Views: 1879

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

If these are numbers, the use division:

select cast(num / 100.0 as decimal(18, 2))

Note that the conversion back to decimal is important, because SQL Server does not specify the precision of the result of a decision (at least not in a form that can be understood by mere mortals; the documentation is here for those interested).

If these are strings, use stuff():

select stuff(num, len(num) - 2, 0, '.')

Upvotes: 5

TcKs
TcKs

Reputation: 26632

DECLARE @Num int = 375512
DECLARE @Num2 real = @Num
SET @Num2 = @Num2 / 100
PRINT @Num2

Upvotes: 3

Related Questions