sql server里的查询结果要保存到一个变量里,怎么弄?

如查询
select count(*) from aa
select count(*) from bb

现在要查两都之差,有没有办法把第一个查询存到一个变量,第二个存到另一个变量,再变量一差就出结果。

我举的比较简单的例子,但有时是很复杂的,需要变量的。

第1个回答  推荐于2018-03-09
举个例子给你:

declare @a int
declare @b int

select @a=count(*) from sysobjects where name like '%sys%'

select @b=count(*) from sysobjects where name like '%set%'

select @a-@b本回答被提问者和网友采纳
第2个回答  2011-10-21
赞同

检举 | 2011-10-21 10:18 lchy0987 | 十一级
举个例子给你:

declare @a int
declare @b int

select @a=count(*) from sysobjects where name like '%sys%'

select @b=count(*) from sysobjects where name like '%set%'

select @a-@b
第3个回答  2011-10-21
从数据库读取出来,然后将读取的内容赋值给变量
第4个回答  2011-10-21
select (select Count(*) from users) usercount,(select Count(*) from ProgramModuleCodes) pcount ,((select Count(*) from ProgramModuleCodes)-(select Count(*) from users)) chabie
我也简单的给些了一个SQL语句 ,,,
第5个回答  2011-10-21
count返回的就是整型,直接int
相似回答