SQL indexOf、lastIndexOf

DECLARE @Name NVARCHAR (50)
SET @Name = 'abcd.12345.efght'

DECLARE @Position INT

--sql first indexof
SET @Position = CHARINDEX('.', @Name);
SELECT SUBSTRING (@Name, 0,@Position)--abcd

--sql last indexof
SET @Position = LEN(@Name) - CHARINDEX('.', REVERSE(@Name)) + 1
SELECT SUBSTRING (@Name, @Position+1,len(@Name)-@Position+1) --efght

posted @ 2016-04-26 15:48  放哨De老鼠  阅读(5134)  评论(0编辑  收藏  举报