每次用的时候都要百度,备忘一下吧。
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)
declare @str varchar(20) set @str = '10*20*300' select reverse(substring(reverse(@str),1,charindex('*',reverse(@str)) - 1))