ssms sql在第一次找到特定字符串后仅返回几个字符

cyej8jka  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(473)

在第一次在列中找到某个字符串后,我尝试只返回9个字符(或总计$amount)。
示例输入1:“您当前欠的金额为5000.00美元,您不欠的金额为2000.00美元”
示例输入2:“您当前欠的金额为0.00美元,您不欠的金额为0.00美元”
示例数据
示例输出1:$5000.00示例输出2:$0.00
示例输出
谢谢!

yvgpqqbh

yvgpqqbh1#

提供的信息很少,我猜这就是你可能看到的。

DECLARE @Desc VARCHAR(100) = 'The amount you currently owe is $1.00 The amount you do not owe is $2,000.00'

 SELECT SUBSTRING(@Desc, PATINDEX('%$%', @Desc), ABS(CHARINDEX(N'.', @Desc, CHARINDEX(N'$', @Desc, 1)) - CHARINDEX(N'$', @Desc, 1)) + 3)

DECLARE @Desc VARCHAR(100) = 'The amount you currently owe is $10.00 The amount you do not owe is $2,000.00'

 SELECT SUBSTRING(@Desc, PATINDEX('%$%', @Desc), ABS(CHARINDEX(N'.', @Desc, CHARINDEX(N'$', @Desc, 1)) - CHARINDEX(N'$', @Desc, 1)) + 3)

DECLARE @Desc VARCHAR(100) = 'The amount you currently owe is $100.00 The amount you do not owe is $2,000.00'

 SELECT SUBSTRING(@Desc, PATINDEX('%$%', @Desc), ABS(CHARINDEX(N'.', @Desc, CHARINDEX(N'$', @Desc, 1)) - CHARINDEX(N'$', @Desc, 1)) + 3)

DECLARE @Desc VARCHAR(100) = 'The amount you currently owe is $1,000.00 The amount you do not owe is $2,000.00'

 SELECT SUBSTRING(@Desc, PATINDEX('%$%', @Desc), ABS(CHARINDEX(N'.', @Desc, CHARINDEX(N'$', @Desc, 1)) - CHARINDEX(N'$', @Desc, 1)) + 3)

DECLARE @Desc VARCHAR(100) = 'The amount you currently owe is $10,000.00 The amount you do not owe is $2,000.00'

 SELECT SUBSTRING(@Desc, PATINDEX('%$%', @Desc), ABS(CHARINDEX(N'.', @Desc, CHARINDEX(N'$', @Desc, 1)) - CHARINDEX(N'$', @Desc, 1)) + 3)

DECLARE @Desc VARCHAR(100) = 'The amount you currently owe is $100,000.00 The amount you do not owe is $2,000.00'

 SELECT SUBSTRING(@Desc, PATINDEX('%$%', @Desc), ABS(CHARINDEX(N'.', @Desc, CHARINDEX(N'$', @Desc, 1)) - CHARINDEX(N'$', @Desc, 1)) + 3)

DECLARE @Desc VARCHAR(100) = 'The amount you currently owe is $1,000,000.00 The amount you do not owe is $2,000.00'

 SELECT SUBSTRING(@Desc, PATINDEX('%$%', @Desc), ABS(CHARINDEX(N'.', @Desc, CHARINDEX(N'$', @Desc, 1)) - CHARINDEX(N'$', @Desc, 1)) + 3)

相关问题