sql 中的 indexOf 与 lastIndexOf

Elysian
2021-09-01 / 0 评论 / 89 阅读 / 正在检测是否收录...
DECLARE @Name NVARCHAR (50)
SET @Name = ‘12345.67890ABCDE.FGHIJKLMNOPQRSTUVWXYZTest’

DECLARE @Position INT

–sql first indexof
SET @Position = CHARINDEX(‘.’, @Name);
SELECT SUBSTRING (@Name, @Position+1,LEN(@Name)-@Position)

–sql last indexof
SET @Position = LEN(@Name) – CHARINDEX(‘.’, REVERSE(@Name)) + 1
SELECT SUBSTRING (@Name, 0, @Position)
0

评论

博主关闭了所有页面的评论