请问在存储过程中可以使用存储过程吗?

zzutnicholas 2009-10-15 02:13:57

ALTER PROCEDURE dbo.GetFamilyParts
(
@node int
)
AS
SET NOCOUNT ON
select a.* from Part a,dbo.GetPartsFamily(@node) b where a.ID=b.Part
return



ALTER PROCEDURE dbo.GetPartsFamily
(
@id int
)
AS
SET NOCOUNT ON
declare @t table (id int,Level int)
declare @Level int
set @Level=0
insert @t values(@id,@Level)
while exists (select 1
from @t t,PartsClass a
where a.Parent=t.id
and t.Level=@Level
)
begin
insert @t select a.id,@Level+1
from @t t,PartsClass a
where a.Parent=t.id
and t.Level=@Level
set @Level = @Level+1
end
Select a.* from PartsClass a,@t t where a.ID=t.id
return




请问我这样写对吗?
...全文
140 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbsh 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 mugua604 的回复:]
你这个用函数解决。。函数是返回值,而存储过程是返回集的!
这个很重要的!
[/Quote]

表值函数
-狙击手- 2009-10-15
  • 打赏
  • 举报
回复
select a.* from Part a, 
OPENROWSET('SQLOLEDB','SERVER=.;UID=sa;PWD=','exec servername.dbo.GetPartsFamily 2') AS
where a.ID=b.Part
-狙击手- 2009-10-15
  • 打赏
  • 举报
回复
select a.* from Part a, 
from OPENROWSET('SQLOLEDB','SERVER=.;UID=sa;PWD=','exec servername.dbo.GetPartsFamily 2') AS
where a.ID=b.Part
--小F-- 2009-10-15
  • 打赏
  • 举报
回复
火龙岛主 2009-10-15
  • 打赏
  • 举报
回复
当然可以, 但如此繁琐设计数据集嵌套的还是写在一起比较好
SQL77 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 janely318 的回复:]
把GetPartsFamily改成函数就行了
[/Quote]
洛洛女侠说得是,可以把后面的那个改成函数,
mugua604 2009-10-15
  • 打赏
  • 举报
回复
你这个用函数解决。。函数是返回值,而存储过程是返回集的!
这个很重要的!
SQL77 2009-10-15
  • 打赏
  • 举报
回复
select a.* from Part a,dbo.GetPartsFamily(@node) b where a.ID=b.Part
这个存储过程要放入另外一个表里面,
君_洛洛 2009-10-15
  • 打赏
  • 举报
回复
把GetPartsFamily改成函数就行了
sgtzzc 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用楼主 zzutnicholas 的回复:]


请问我这样写对吗?
[/Quote]

不对,执行存储过程用 exec 存储过程名
水族杰纶 2009-10-15
  • 打赏
  • 举报
回复
--不對,可以將存儲過程結果放進臨時表 然後join
create table #t (collist ....)
insert #t exec dbo.GetPartsFamily(@node)
select * .....
SQL77 2009-10-15
  • 打赏
  • 举报
回复
当然可以调用
xiequan2 2009-10-15
  • 打赏
  • 举报
回复
请问在存储过程中可以使用存储过程吗? 可以

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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