我在postgres上运行了一个查询,我需要转换它,因为它应该在MS-SQL Server上运行。
case when position('.' in campo30) >= 1
then CAST(replace(replace(CAMPO30,'.',''),',','.') AS FLOAT)
else CAST(replace(CAMPO30,',','.') AS FLOAT)
end
MS-SQL Server的等效代码是什么?
答案 0 :(得分:0)
在SQL-Server上使用CHARINDEX
CHARINDEX(expressionToFind,expressionToSearch [,start_location])
DECLARE @CAMPO30 varchar(64) = '2,663.25';
SELECT CASE WHEN CHARINDEX('.', @CAMPO30) > 1
THEN CAST(REPLACE(REPLACE(@CAMPO30,'.',''),',','.') AS FLOAT)
ELSE CAST(REPLACE(@CAMPO30,',','.') AS FLOAT)
END AS CAMPO30
GO
| CAMPO30 |
| ------: |
| 2.66325 |
dbfiddle here