| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付赛孚耐:软件保护加密专家
身份认证令牌USB KEY   
共有 627 人关注过本帖
标题:这样写错在哪?(游标)
收藏  订阅  推荐  打印 
killer_l
Rank: 6Rank: 6
等级:金牌会员
威望:3
帖子:1140
积分:12685
注册:2007-5-25
这样写错在哪?(游标)


程序代码:
declare @xx char(20),@yy char(20) ,@zz char(20)
declare zz cursor for
select 员工号,姓名,缺勤名称 from JBQK a, QQLX b where a.缺勤类型 = b.缺勤类型 and a.缺勤天数 = 1
print '缺勤天数为1天的'
open zz
fetch next from zz into @xx,@yy,@zz
while @@fetch_status = 0
begin
    fetch next from zz into @xx,@yy,@zz
    print '员工号'++'              '+'姓名'+'               '+'缺勤名称'
        print @xx +@yy + @zz
end
close zz

declare yy cursor for
select 员工号,姓名,缺勤名称 from JBQK a, QQLX b where a.缺勤类型 = b.缺勤类型 and a.缺勤天数 = 2
print '---------------------'
print '缺勤天数为2天的'
open yy
fetch next from yy into @xx,@yy,@zz
while @@fetch_status = 0
begin
    fetch next from yy into @xx,@yy,@zz
    print '员工号'++'              '+'姓名'+'               '+'缺勤名称'
        print @xx +@yy + @zz
    
    
end
close yy
结果查出来两个结果一样的
员工号              姓名               缺勤名称
5                   邓刚                病假   
---------------------
缺勤天数为2天的
员工号              姓名               缺勤名称
4                   张晓华              事假               
员工号              姓名               缺勤名称
4                   张晓华              事假      
搜索更多相关主题的帖子: 游标  
2007-11-29 19:05
purana
Rank: 12Rank: 12Rank: 12
来自:广东-广州
等级:版主
威望:66
帖子:6040
积分:61390
注册:2005-6-17

while @@fetch_status = 0
begin
        
        print '员工号'++'              '+'姓名'+'               '+'缺勤名称'
        print @xx +@yy + @zz
        fetch next from yy into @xx,@yy,@zz
        
end

--试试这样子?

我的msn: myfend@hotmail.com
2007-11-29 20:29
XieLi
Rank: 4
等级:高级会员
威望:1
帖子:759
积分:7930
注册:2007-7-24

declare @xx char(20),@yy char(20) ,@zz char(20)
DECLARE @INT INT,@INT2 INT
SET @INT=1
SET @INT2=1
declare zz cursor for
select 员工号,姓名,缺勤名称 from JBQK a, QQLX b where a.缺勤类型 = b.缺勤类型 and a.缺勤天数 = 1
print '缺勤天数为1天的'
open zz
fetch next from zz into @xx,@yy,@zz
while @@fetch_status = 0
begin
        
        IF @INT=1
             BEGIN
                  print '员工号'++'              '+'姓名'+'               '+'缺勤名称'
             END
        print @xx +@yy + @zz
    SET @INT=@INT+1
        fetch next from zz into @xx,@yy,@zz
end
close zz

declare yy cursor for
select 员工号,姓名,缺勤名称 from JBQK a, QQLX b where a.缺勤类型 = b.缺勤类型 and a.缺勤天数 = 2
print '---------------------'
print '缺勤天数为2天的'
open yy
fetch next from yy into @xx,@yy,@zz
while @@fetch_status = 0
begin
        
            IF @INT2=1
             BEGIN
                  print '员工号'++'              '+'姓名'+'               '+'缺勤名称'
             END
        
        print @xx +@yy + @zz
        SET @INT2=@INT2+1
        fetch next from yy into @xx,@yy,@zz
        
        
end
close yy



这样应该可以的!

拥有蓝天的白云,拥有你的我.
2007-11-29 22:03
killer_l
Rank: 6Rank: 6
等级:金牌会员
威望:3
帖子:1140
积分:12685
注册:2007-5-25

谢谢两位了

2007-11-30 16:01
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.057953 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved