SQL游標示例

2021-04-20 12:27:02 字數 490 閱讀 3447

declare @userid char(6)

declare @username varchar(20)

declare @email varchar(200)

declare testcur cursor for

select userid,username,email from tbusercommon

open testcur

fetch next from testcur into @userid,@username,@email

while @@fetch_status=0

begin

print @userid 

print @username

print @email

fetch next from testcur into @userid,@username,@email

endclose testcur

deallocate testcur

SQL 游標示例

1 declare iint 2declare teststr varchar 50 3 set i 0 給初始值45 create table temp test 建立臨時表6 7 num varchar 50 8 9while i 10 10begin 11insert into temp te...

SQL Server 游標示例

建立測試臨時表 if object id tempdb.books is not null begin drop table books endcreate table books bookname nvarchar 20 bookcode nvarchar 20 insert into books...

sql游標用法示例

declare ida smalldatetime declare icd int declare s cursor cursor for select date,cid from dayrecomstat group by date order by date open s cursor fetc...