-
Notifications
You must be signed in to change notification settings - Fork 0
6. CHARINDEX Advance
thuantt0101 edited this page Jul 2, 2019
·
1 revision
GO
/****** Object: StoredProcedure [dbo].[sp_TEST] Script Date: 02/07/2019 8:47:46 SA ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_TEST]
AS
BEGIN
declare @_String nvarchar(4000) = ''
declare @_substring nvarchar(4000) = ''
declare @_length int = 0
declare @_index1 int = 0
declare @_index2 int = 0
set @_String = 'Thuantt@TienTT@'
set @_length = LEN(@_String)
print(@_length);
while(@_index2<@_length)
begin
set @_index2 = CHARINDEX('@',@_String,@_index2+1);
IF(@_Index2 = 0)
BREAK
set @_substring = SUBSTRING(@_String,@_index1,@_index2-@_index1);
print(@_substring)
set @_index1 = @_index2+1
end
END
GO
EXEC sp_TEST