我有以下变量:
DECLARE @test nvarchar(100)
SET @test = 'Prodcut A (Average: 1.000)'
SET @test = 'Prodcut B (Average: 2.3500)'
我的输出应该是:Prodcut A(平均:1.0),Prodcut B(平均:2.35)
如何从 SQL Server 中的 nvarchar 数据类型列中删除所有尾随零?我确信我必须使用 SUBSTRING 和 CHARINDEX 但不确定如何使用。有人可以帮帮我吗?
我尝试了以下方法:
IF charindex('.', @test ) > 0
select SUBSTRING(@test, PATINDEX('%[^0 ]%', @test+ ' '), LEN(@test))
End