我又写了个返回变量是表的存储过程,但是编译时第3行出错 在关键字 'table' 附近有语法错误create proc csdn @in int, @tem table(id int,level int) output/////////////////////////// as begin declare @level int set @level=1 insert into @tem select @in,@level while @@rowcount>0 begin insert into @tem select m.m_id from model m join @tem t where m.pm_id=t.node and t.level=@level-1 set @level=@level+1 end end
model表SQL如下:CREATE TABLE [dbo].[model] ( [m_id] [int] IDENTITY (1, 1) NOT NULL , [m_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [pm_id] [int] NULL , [flag] [bit] NULL ) ON [PRIMARY] GO
create function csdn(@in int) returns @tem table(id int,level int) as begin declare @level int set @level=1 insert into @tem select @in,@level while @@rowcount>0 begin set @level=@level+1 insert into @tem select m.m_id from model m,@tem t where m.pm_id=t.node and t.level=@level-1 end return end goselect * from csdn(4) godrop function csdn
樓主﹕你在存儲過程里用了output類型想將查詢出來的結果輸入 可是在偉遞參數的時候可不要忘了加output declare @out int exec fir 4,@out output print @out
函数可以随处调用。存储过程是保存起来的可以接受和返回用户提供的参数的 Transact-SQL 语句的集合。
可以创建一个过程供永久使用,或在一个会话中临时使用(局部临时过程),或在所有会话中临时使用(全局临时过程)。
也可以创建在 Microsoft SQL Server启动时自动运行的存储过程。用户定义函数,它是返回值的已保存的 Transact-SQL 例程。用户定义函数不能用于执行一组修改全局数据库状态的操作。
与系统函数一样,用户定义函数可以从查询中唤醒调用。也可以像存储过程一样,通过 EXECUTE 语句执行。
在关键字 'table' 附近有语法错误create proc csdn
@in int,
@tem table(id int,level int) output///////////////////////////
as
begin
declare @level int
set @level=1
insert into @tem select @in,@level
while @@rowcount>0
begin
insert into @tem select m.m_id from model m join @tem t where m.pm_id=t.node and t.level=@level-1
set @level=@level+1
end
end
[m_id] [int] IDENTITY (1, 1) NOT NULL ,
[m_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[pm_id] [int] NULL ,
[flag] [bit] NULL
) ON [PRIMARY]
GO
returns @tem table(id int,level int)
as
begin
declare @level int
set @level=1
insert into @tem select @in,@level
while @@rowcount>0
begin
set @level=@level+1
insert into @tem select m.m_id
from model m,@tem t
where m.pm_id=t.node
and t.level=@level-1
end
return
end
goselect * from csdn(4)
godrop function csdn
可是在偉遞參數的時候可不要忘了加output
declare @out int
exec fir 4,@out output
print @out