@Begin int,
@Ending int
AS
declare @sSql varchar(500),@sStr varchar(500)
set @sSql= '(select * from titles where title_id is not null '
if @Begin ='1'
set @sSql=@sSql+'and pub_id=''0877'''
if @Ending <>''
set @sSql=@sSql+'and type=''mod_cook'''
set @sSql=@sSql + ') temp'
set @sStr='select * into ##bb from'+ (@sSql)
exec(@sStr)
select * into #temp from ##bb
drop table ##bb--一定要销毁全局临时表
——##标识全局临时表,#标识局部临时表
本文介绍了一段SQL脚本,展示了如何使用SQL创建并操作局部与全局临时表。通过条件判断来动态构建SQL语句,并执行存储过程来实现数据的筛选与存储。最后确保清理了创建的全局临时表。
1565

被折叠的 条评论
为什么被折叠?



