请求援助!存储过程....在线等...

ilmself0451 2004-10-09 10:33:44


我想使用存储过程得到与一个属性相关的几个表中的统计数据
形式大概如下
传入数据库一属性
传出此属性的信息总数(count)和在另一个表中的信息总数和前一个表的总和。

我的数据库是这样的
表一 T1
id bigint PK
test int
在表一中,select count(*) from t1 where test = 1
时候,结果是5

表二 T2
id bigint PK
foo int
在表二中,select count(*) from t1 where foo = 1
时候,结果是8

我所期望的存储过程工作是这样的
我传入一个参数 a = 1
然后 传出的数据是
5 13
就是第一个表的test=1的信息总数 就两个表的属性为1的所有信息总数

我该怎么写这个存储过程, 朋友们帮帮忙

...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ilmself0451 2004-10-11
  • 打赏
  • 举报
回复
谢谢,再来一个
http://community.csdn.net/Expert/topic/3444/3444117.xml?temp=.4150049

帮忙看一下,谢谢.......


双管放分...嘻嘻, 就是少了点!
erlengzi1982 2004-10-09
  • 打赏
  • 举报
回复
create procedure ppp
@a int, @c1 int out, @c2 int out
as
select @c1=count(*) from t1 where test =@a
select @c2=count(*) from t1 where foo =@a
select @t,@f
go
erlengzi1982 2004-10-09
  • 打赏
  • 举报
回复
如果你只是要显示出来,按照上面那位仁兄的方法就可以了,如果你还想利用这个结果的数据,那么最好在定义存储过程时候,多添加两个输出参数!
General521 2004-10-09
  • 打赏
  • 举报
回复
上面错了:重来
create procedure ppp
@a int
as
declare @t int
declare @f int
select @t=count(*) from t1 where test =@a
select @f=count(*) from t1 where foo =@a
select @t,@f
go
General521 2004-10-09
  • 打赏
  • 举报
回复
create procedure ppp
@a int
as
declare @t int
declare @f int
select @t=count(*) from t1 where test = 1
select @f=count(*) from t1 where foo = 1
select @t,@f
go

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧