While Loop Problem in SQL
-
DECLARE @spot SMALLINT DECLARE @str VARCHAR(8000) DECLARE @strQuery nVARCHAR(1000) DECLARE @sql VARCHAR(8000) DECLARE @cslist VARCHAR(8000) declare @Count int set @Count=0 set @cslist='CallLog1230,CallLog2230' MainLoop: WHILE @cslist <> '' BEGIN SET @spot = CHARINDEX(',', @cslist) print @spot IF @spot>0 BEGIN SET @str = CAST(LEFT(@cslist, @spot-1) AS varchar) SET @cslist = RIGHT(@cslist, LEN(@cslist)-@spot) print @cslist goto InComing goto OutGoing END ELSE BEGIN SET @str = CAST(@cslist AS varchar) SET @cslist = '' print @str if(@Count=0) Begin set @Count=1 goto InComing goto OutGoing End Else goto EndLoop END End InComing: Begin print 'IN' print @str End OutGoing: Begin print 'OUT' print @str goto MainLoop End EndLoop: return I am not return from the While loop Please help me to find where i am wrong
-
DECLARE @spot SMALLINT DECLARE @str VARCHAR(8000) DECLARE @strQuery nVARCHAR(1000) DECLARE @sql VARCHAR(8000) DECLARE @cslist VARCHAR(8000) declare @Count int set @Count=0 set @cslist='CallLog1230,CallLog2230' MainLoop: WHILE @cslist <> '' BEGIN SET @spot = CHARINDEX(',', @cslist) print @spot IF @spot>0 BEGIN SET @str = CAST(LEFT(@cslist, @spot-1) AS varchar) SET @cslist = RIGHT(@cslist, LEN(@cslist)-@spot) print @cslist goto InComing goto OutGoing END ELSE BEGIN SET @str = CAST(@cslist AS varchar) SET @cslist = '' print @str if(@Count=0) Begin set @Count=1 goto InComing goto OutGoing End Else goto EndLoop END End InComing: Begin print 'IN' print @str End OutGoing: Begin print 'OUT' print @str goto MainLoop End EndLoop: return I am not return from the While loop Please help me to find where i am wrong
Remove "goto MainLoop" from bottom of "OutGoing:"
Hardik Panchal