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
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
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
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
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
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
插入错误: 列名或所提供值的数目与表定义不匹配。
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
这样就对了