SQL函数参数调用

FlashK 2008-03-31 08:53:42

select distinct table_A.Table_Description,
(
select Count(*) from F_User_BBB('20',table_A.Table_Description)
)
from F_User_AAA('20') as table_A


可不可以将一个函数返回的结果作为另一个函数的参数?

我希望的效果为
AAA 2
BBB 3
CCC 0
...全文
210 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
FlashK 2008-04-01
已经有数据了,现在能不能实现这样的结果,帮个忙了
  • 打赏
  • 举报
回复
FlashK 2008-03-31


create table tb(id int,sort int,sortName varchar(10))
insert into tb select 1,'20','AAA'
insert into tb select 2,'20','BBB'
insert into tb select 3,'20','AAA'
insert into tb select 4,'20','CCC'

go

IF EXISTS(SELECT *
FROM sysobjects
WHERE name = 'fun_AAA'
AND type = 'TF')
drop function fun_AAA
go
create function fun_AAA(@sort int)
returns @table table(
Id int,
sort int,
sortname varchar(10)
) with encryption
begin
Insert into @table
select * from tb where sort=@sort
return
end
go

select distinct sortname from dbo.fun_AAA('20')




create table tb1(id int,sortName varchar(10),field1 varchar(20))
insert into tb1 select 1,'AAA','aaaa'
insert into tb1 select 2,'BBB','adsfasd'
insert into tb1 select 3,'AAA','asdfasd'
insert into tb1 select 4,'AAA','adsfasd'

go

IF EXISTS(SELECT *
FROM sysobjects
WHERE name = 'fun_BBB'
AND type = 'TF')
drop function fun_BBB
go
create function fun_BBB(@sortname varchar(10))
returns @table table(
Id int,
sortname varchar(10),
field1 varchar(20)
) with encryption
begin
Insert into @table
select * from tb1 where sortname=@sortname
return
end
go

select count(*) from dbo.fun_BBB('AAA')


select distinct table_A.sortName,
(
select Count(*) from fun_BBB(table_A.sortName)
)
from fun_AAA('20') as table_A

-----------------------
AAA 3
BBB 1
CCC 0
  • 打赏
  • 举报
回复
wzy_love_sly 2008-03-31
create table tb(id int,name varchar(10))
insert into tb select 1,'a'
insert into tb select 2,'b'
insert into tb select 3,'aa'
insert into tb select 4,'bb'


create function fun_tb(@name varchar(10))
returns table
as
return select * from tb where name like '%'+@name+'%'

select * from dbo.fun_tb('a')


1 a
3 aa

估计是表值函数
  • 打赏
  • 举报
回复
pt1314917 2008-03-31
[Quote=引用 2 楼 FlashK 的回复:]
SQL code
Select distinct Table_Description From F_User_AAA
-------------------------------------------------
AAA
BBB
CCC

select Count(*) from F_User_BBB('20','AAA')
---------------------------------------------
2
[/Quote]


F_User_BBB,这个是什么?
  • 打赏
  • 举报
回复
hery2002 2008-03-31
[Quote=引用 1 楼 pt1314917 的回复:]
楼主给点数据噢。光给结果也不行啊
[/Quote]
  • 打赏
  • 举报
回复
FlashK 2008-03-31

Select distinct Table_Description From F_User_AAA
-------------------------------------------------
AAA
BBB
CCC

select Count(*) from F_User_BBB('20','AAA')
---------------------------------------------
2

  • 打赏
  • 举报
回复
pt1314917 2008-03-31
楼主给点数据噢。光给结果也不行啊
  • 打赏
  • 举报
回复
发帖
MS-SQL Server

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
帖子事件
创建了帖子
2008-03-31 08:53
社区公告
暂无公告