1. 程式人生 > >SQL Server 遊標運用:滑鼠軌跡字串分割

SQL Server 遊標運用:滑鼠軌跡字串分割

--滑鼠軌跡字串分割
DECLARE @ID int,@PosSet VARCHAR(2000)
DECLARE @splitlen INT
DECLARE @split NVARCHAR(10)
DECLARE @temp VARCHAR(100)
DECLARE @PosSet_x INT
DECLARE @PosSet_y INT
DECLARE @PosTime DATETIME
SET @split = ']'
DECLARE @itemCur CURSOR
SET @itemCur = CURSOR FOR 
    SELECT ID,PosSet FROM [VisiteLog
] WHERE PosSet <> '' OPEN @itemCur FETCH NEXT FROM @itemCur INTO @ID,@PosSet WHILE @@FETCH_STATUS=0 BEGIN SET @splitlen=LEN(@split+'a')-2 WHILE CHARINDEX(@split,@PosSet)>0 BEGIN SET @Temp = LEFT(@PosSet,CHARINDEX(@split,@PosSet)-1) SET @Temp = replace
(replace(@Temp,',[',''),'[','') SET @PosSet_x = dbo.Get_StrArrayStrOfIndex(@Temp,',',1) SET @PosSet_y = dbo.Get_StrArrayStrOfIndex(@Temp,',',2) SET @PosTime = dbo.Get_StrArrayStrOfIndex(@Temp,',',3) INSERT PosSetInfo VALUES(@ID,@PosSet_x,@PosSet_y,@PosTime)
SET @PosSet=STUFF(@PosSet,1,CHARINDEX(@split,@PosSet)+@splitlen,'') END FETCH NEXT FROM @itemCur INTO @ID,@PosSet END CLOSE @itemCur DEALLOCATE @itemCur