to to pbsql(风云):
非常感谢,你是对的,但我还有一点不明白就是下面的代码结果为什么是许多条一样的结果?
declare @t varchar(100),@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
select @t
set @n=@n-1
end
是不是
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
这句话每次选出来的是最前面的一个?
你错了:
declare @t varchar(100),@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
exec('drop table '+@t)
set @n=@n-1
end
用
declare @t varchar(100),@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
set @n=@n-1
end
还是一样呀!!!!!!!
to to pbsql(风云):
但还是不对,我用下面的代码测试:
declare @t varchar,@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
set @n=@n-1
end
时看见结果都是是我想要的表名;但用下面的代码时
eclare @t varchar,@n int
select @n=count(*) from sysobjects where xtype='u' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
select @t
set @n=@n-1
end
结果都变成了'R',真的搞不懂为什么?
to pbsql(风云):
当有很多条时,我用
eclare @t varchar,@n int
select @n=count(*) from sysobjects where xtype='u' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
exec('drop table '+@t)
set @n=@n-1
end
为什么不对?
declare @tblname varchar(30)
declare cursorName cursor
for
Select Name from sysobjects
where Xtype='U' and
datediff(day,crdate,getdate())=0
open cursorName
fetch next from cursorName into @tblname
while @@fetch_status=0
begin
exec('drop table '+@tblname)
fetch next from cursorName into @tblname
end
close cursorName
deallocate cursorName
declare @tb varchar(100)
if exists(select * from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0)
begin
select @tb=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
exec('drop table '+@tb)
end