为什么这段执行后显示不出结果来?

Zi_Yuan 2009-02-17 05:39:31
declare @theDate datetime,@evi_date datetime
set @theDate='2009-01-11'
while @theDate>@evi_date
begin
DECLARE evi_cursor CURSOR FOR
select evi_date from evidence
--打开游标
OPEN evi_cursor
--取出值
FETCH NEXT FROM evi_cursor INTO @evi_date
select @evi_date
--循环取出游标的值
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM evi_cursor
INTO @evi_date

end
CLOSE evi_cursor --关闭游标
DEALLOCATE evi_cursor --释放游标
end
...全文
55 10 点赞 打赏 收藏 举报
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
-狙击手- 2009-02-17
[Quote=引用 8 楼 contendskyline 的回复:]
我个人认为不显示结果的原因可能是是:datetime类型的数据不能直接比较大小!
[/Quote]

可以的
  • 打赏
  • 举报
回复
Zi_Yuan 2009-02-17
if exists (select 1 from sysobjects
where id = object_id('evi_date') and type = 'U')
drop table evi_date
create table evi_date(evi_id int,evi_date datetime)
declare @theDate datetime,@evi_date datetime,@evi_id int
set @theDate='2009-01-12'
DECLARE evi_cursor CURSOR FOR
select evi_id,evi_date from evidence order by evi_date
--打开游标
OPEN evi_cursor
--取出值
FETCH NEXT FROM evi_cursor INTO @evi_id,@evi_date
print @evi_id
print @evi_date

--循环取出游标的值
WHILE @@FETCH_STATUS = 0
BEGIN
--print @evi_date

if(@theDate<@evi_date) break
insert into evi_date (evi_id,evi_date) values(@evi_id,@evi_date)
FETCH NEXT FROM evi_cursor
INTO @evi_id,@evi_date
end
CLOSE evi_cursor --关闭游标
DEALLOCATE evi_cursor --释放游标

select * from evi_date


这样就对了
  • 打赏
  • 举报
回复
contendskyline 2009-02-17
我个人认为不显示结果的原因可能是是:datetime类型的数据不能直接比较大小!
  • 打赏
  • 举报
回复
Zi_Yuan 2009-02-17
if exists (select 1 from sysobjects
where id = object_id('evi_date') and type = 'U')
drop table evi_date
create table evi_date(evi_id int,evi_date datetime)
declare @theDate datetime,@evi_date datetime,@evi_id int
set @theDate='2009-01-12'
DECLARE evi_cursor CURSOR FOR
select evi_id,evi_date from evidence order by evi_date
--打开游标
OPEN evi_cursor
--取出值
FETCH NEXT FROM evi_cursor INTO @evi_id,@evi_date

--循环取出游标的值
WHILE @@FETCH_STATUS = 0
BEGIN
--print @evi_date
if(@theDate<@evi_date) break
insert into evi_date values(@evi_id,@evi_date)
FETCH NEXT FROM evi_cursor
INTO @evi_id,@evi_date
end
CLOSE evi_cursor --关闭游标
DEALLOCATE evi_cursor --释放游标

select * from evi_date

服务器: 消息 213,级别 16,状态 5,行 19
插入错误: 列名或所提供值的数目与表定义不匹配。
  • 打赏
  • 举报
回复
you_tube 2009-02-17
declare @theDate datetime,@evi_date datetime
set @theDate='2009-01-11'
while @theDate>@evi_date
begin
DECLARE evi_cursor CURSOR FOR
select evi_date from evidence
--打开游标
OPEN evi_cursor
--取出值
FETCH NEXT FROM evi_cursor INTO @evi_date

--循环取出游标的值
WHILE @@FETCH_STATUS = 0
BEGIN
select @evi_date

FETCH NEXT FROM evi_cursor
INTO @evi_date

end
CLOSE evi_cursor --关闭游标
DEALLOCATE evi_cursor --释放游标
end
  • 打赏
  • 举报
回复
moon&sean 2009-02-17
应该这样写:
declare @theDate datetime,@evi_date datetime
set @theDate='2009-01-11'
while @theDate>@evi_date
begin
DECLARE evi_cursor CURSOR FOR
select evi_date from evidence
--打开游标
OPEN evi_cursor
--取出值
FETCH NEXT FROM evi_cursor INTO @evi_date

--循环取出游标的值
WHILE @@FETCH_STATUS = 0
BEGIN
select @evi_date
FETCH NEXT FROM evi_cursor
INTO @evi_date

end
CLOSE evi_cursor --关闭游标
DEALLOCATE evi_cursor --释放游标
end
  • 打赏
  • 举报
回复
Zi_Yuan 2009-02-17
消息里面总是出现“命令已成功完成。”,显示不出值
  • 打赏
  • 举报
回复
-狙击手- 2009-02-17
declare @theDate datetime,@evi_date datetime
set @theDate='2009-01-11'
while @theDate>@evi_date
begin
DECLARE evi_cursor CURSOR FOR
select evi_date from evidence
--打开游标
OPEN evi_cursor
--取出值
FETCH NEXT FROM evi_cursor INTO @evi_date

--循环取出游标的值
WHILE @@FETCH_STATUS = 0
BEGIN
select @evi_date
FETCH NEXT FROM evi_cursor
INTO @evi_date

end
CLOSE evi_cursor --关闭游标
DEALLOCATE evi_cursor --释放游标
end
  • 打赏
  • 举报
回复
rucypli 2009-02-17
哪里有显示结果的代码
  • 打赏
  • 举报
回复
Zi_Yuan 2009-02-17
实际上是有记录的
  • 打赏
  • 举报
回复
相关推荐
发帖
MS-SQL Server
加入

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2009-02-17 05:39
社区公告
暂无公告