標籤:sqlserver 遊標
DECLARE TEMP_CURSOR CURSOR SCROLL FOR SELECT CityName FROM CoreLinkLinShi -- 此處必須有Sql語句,不能空著 OPEN TEMP_CURSOR DECLARE @CityName varchar(50) FETCH NEXT FROM TEMP_CURSOR INTO @CityName WHILE @@FETCH_STATUS=0 BEGIN DECLARE @VALIDTIME VARCHAR(19),@ENDTIME VARCHAR(19) SET @VALIDTIME=CONVERT(CHAR(10),GETDATE(),23)+‘ 00:00:00‘ SET @ENDTIME=CONVERT(CHAR(10),DATEADD(DAY,1,GETDATE()),23)+‘ 00:00:00‘ WHILE(CONVERT(DATETIME,@VALIDTIME) < CONVERT(DATETIME,@ENDTIME)) BEGIN INSERT INTO dbo.CoreLink_temp(CityName,CompanyNo,SvrID,NeID,NeName,Slot,BoardName,Port,ValidTime) VALUES(@CityName,@CompanyNo,@SvrID,@NeID,@NeName,@Slot,@BoardName,@Port,@VALIDTIME) SET @VALIDTIME= CONVERT(CHAR(19),DATEADD(MI,15,CONVERT(DATETIME,@VALIDTIME)),120) END FETCH NEXT FROM TEMP_CURSOR INTO @CityName END CLOSE TEMP_CURSOR DEALLOCATE TEMP_CURSOR
本文出自 “默默” 部落格,請務必保留此出處http://ruiwen.blog.51cto.com/8852761/1564195
SQLServer遊標的用法