SQL 游标使用例子
作者:hycn 日期:2008-09-28
SQL Server中使用游标的一个例子
比较简单,不过应该可以解决一些使用中的疑惑
--声明变量--
DECLARE @total int,@xid int
DECLARE contact_cursor CURSOR FOR
--取得数据
select count(cid) as total,xid
from zzx_course group by xid
--打开游标
OPEN contact_cursor
WHILE(@@fetch_status=0)--让游标循环起来吧
BEGIN
FETCH NEXT FROM contact_cursor into @total,@xid --这里把取到的内容暂存
select @total as total,@xid as xid --
Update xclass SET xtotal = @total Where xid =@xid
END
--关闭游标
CLOSE contact_cursor
--删除内存
DEALLOCATE contact_cursor
你可能对以下内容也感兴趣:
SQL截取字符函数 英文 中文
SqlDbType.NText 16
比较简单,不过应该可以解决一些使用中的疑惑
--声明变量--
DECLARE @total int,@xid int
DECLARE contact_cursor CURSOR FOR
--取得数据
select count(cid) as total,xid
from zzx_course group by xid
--打开游标
OPEN contact_cursor
WHILE(@@fetch_status=0)--让游标循环起来吧
BEGIN
FETCH NEXT FROM contact_cursor into @total,@xid --这里把取到的内容暂存
select @total as total,@xid as xid --
Update xclass SET xtotal = @total Where xid =@xid
END
--关闭游标
CLOSE contact_cursor
--删除内存
DEALLOCATE contact_cursor
你可能对以下内容也感兴趣:
SQL截取字符函数 英文 中文
SqlDbType.NText 16
SqlDbType.NText 16
作者:hycn 日期:2008-09-26
一个存储过程中用的SqlDbType.NText,16,结果只存16个字符,把16改为0正常
你可能对以下内容也感兴趣:
SQL截取字符函数 英文 中文
查找页面中所有的TextBox并初始为一定的值
Tags: SQL
- 1







