sql查询语句怎么写( 二 )


from tablename a left join tablename b on a.宾馆名称=b.宾馆名称 and a.房间号=b.房间号 where datediff(s,a.入住时间,b.入住时间)
6. 这种SQL(查询所有)语句该怎么写 这个没有直接的解决办法,只能曲线解决
用exec
create procedure mypro(@table varchar(100)) as
begin
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[temp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[temp]
declare @str varchar(5000),@sql varchar(300),@yuju varchar(1000)
set @sql='select yuju into temp from '[email protected] --这里先生成动态语句,把表名间接改成temp
exec( @sql)
declare c cursor for select yuju from temp --这里直接写成temp
open c
fetch c into @yuju
while @@fetch_status=0
begin
exec(@yuju)
print @yuju
fetch c into @yuju
end
close c
deallocate c
return
end