sql 表變量的使用
阿新 • • 發佈:2017-05-21
tex rtti ast select cti 感覺 end basic p s a.Com_SiteGroupID=b.Com_SiteGroupID where [email protected]
and a.SiteID in (select * from @aaa)
and a.CreateTime>[email protected] and a.CreateTime<[email protected] group by c.ObjectText
最近第一次使用sql表變量,感覺挺好用,案例如下:
declare @aaa table(Com_SiteGroupID uniqueidentifier) --定義表變量
---往表變量裏寫數據
insert into @aaa select Com_SiteGroupID from Com_SiteGroup where Com_StructureID [email protected]
union all
select a.Com_SiteBasicID from Com_SiteBasic a inner join Com_SiteGroup b on
--讀取表變量的數據
insert into #temp select c.ObjectText,count(*) as CountNum from Sip_HiddenDisposalInfo a
inner join Sc_InspectionContent b
on a.Sc_InspectionContentID=b.Sc_InspectionContentId inner join Sc_InspectionItem c
on b.Sc_InspectionItemId=c.Sc_InspectionItemId where c.CheckLevel=2
and a.CreateTime>[email protected] and a.CreateTime<[email protected] group by c.ObjectText
sql 表變量的使用