1

How to find place of decimal point in a decimal number in SQL Server using sql query

example:

123567.89

output:7

4

2 回答 2

2
select charindex('.', cast(123567.89 as varchar))

SQLFiddle 演示

于 2013-10-28T16:32:28.643 回答
0
declare @T decimal(38,1) = 1234567890123456789012345678901234567.1;
select charindex('.', cast(@T as varchar(40)));

如果只使用varchar,则默认大小为30;因此,它会失败。除此之外,如果这是在计算列中并且使用了 varchar,则默认大小为 1。

40 = 38 +“小数点”加“符号”

--select charindex('.', cast(@T as varchar)); -- Uncomment and it'll fail
于 2013-10-28T17:49:09.567 回答