在一个数据库里查询和操作其他数据库里的表
use test2 -- 使用第二个数据库里联合其他两个数据里的数据go --tableFlag为那个数据库的标识select * from(select [name],1 as tableFlag from test2..[user] --第一个数据库unionselect [name], 2 as ...
创建全局临时表和局部临时表
--临时表存在于系统数据库tempdb内全局的临时表使用##即两个#号例--判断临时表是否存在if (object_id('tempdb..##tempTable') is not null)begin print 1 drop table iweix.##tempTableend...
使用临时变量创建临时表
declare @tempTabel table( id int primary key identity, [name] nvarchar(200))insert into @tempTabel ([name]) values('wode')insert into @tempTabel ([name]) values('aaaa')select * from @tempTab...
执行sql语句给外部变量赋值
declare @siteArray nvarchar(max) ---存储用户的所有站点declare @guid nvarchar(max) ---存储站点的所有产品set @siteArray=''--设置用户的所有站点select @siteArray=@siteArray...