提示必须声明@table 求助F姐姐 tony哥 乌龟哥 77哥 老黎哥

sxiaohui8709253 2010-05-08 01:56:55
create function GetAllParents(@ID int)
returns @table table(ID int)
as
begin
declare @ParentID int
set @ParentID=@ID
while @ParentID<>0
begin
insert into @table(ID) select ID from A where ParentID= @ParentID
set @ParentID=(select top 1 ID from @table order by ID desc)
end
return @table
end

消息 137,级别 15,状态 2,过程 GetAllParents,第 12 行
必须声明标量变量 "@table"。
...全文
126 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
htl258_Tony 2010-05-08
  • 打赏
  • 举报
回复
不好意思,来晚了
sxiaohui8709253 2010-05-08
  • 打赏
  • 举报
回复
我终于搞出来 大家别笑话我啊
ALTER function [dbo].[GetAllParents](@ID int)
returns @table table(ID int)
as
begin
insert into @table(ID)values(@ID)
declare @ParentID int
set @ParentID=(select ParentID from A where ID=@ID)
insert into @table(ID)values(@ParentID)
while @ParentID<>0
begin
set @ParentID=(select ParentID from A where ID=@ParentID)
insert into @table(ID)values(@ParentID)
end
return
end

赶紧来人
结贴给分了
you_tube 2010-05-08
  • 打赏
  • 举报
回复
老黎 2010-05-08
  • 打赏
  • 举报
回复
惊见大名在标题,特来学习表值函数
向小宋学习
永生天地 2010-05-08
  • 打赏
  • 举报
回复
表值函数,最后直接写return
sxiaohui8709253 2010-05-08
  • 打赏
  • 举报
回复

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER function [dbo].[GetAllParents](@ID int)
returns @table table(ID int)
as
begin
declare @ParentID int
insert into @table(ID) select ParentID from A where ID=@ID
set @ParentID=@ID
while @ParentID<>0
begin
set @ParentID=(select ParentID from A where ID= @ParentID)
insert into @table select * from [dbo].[GetAllParents](@ParentID)
end
return
end
亮剑_ 2010-05-08
  • 打赏
  • 举报
回复
四个哥哥去拍三国了,今天演“三英战吕布”
姐姐演貂婵,今天休息在家
wzy_love_sly 2010-05-08
  • 打赏
  • 举报
回复
77哥,这位应该是小弟弟
--小F-- 2010-05-08
  • 打赏
  • 举报
回复
insert into @table(ID) select ID from A where ParentID= @ParentID
set @ParentID=(select top 1 ID from @table order by ID desc)
end
return @table
end
sxiaohui8709253 2010-05-08
  • 打赏
  • 举报
回复
他们一个都不来 我表示 我很伤心
feixianxxx 2010-05-08
  • 打赏
  • 举报
回复
标题 写得倒是蛮全的 呵呵
miss_chen106 2010-05-08
  • 打赏
  • 举报
回复
路过学习
fa_ge 2010-05-08
  • 打赏
  • 举报
回复

create function GetAllParents(@ID int)
returns @table table(ID int)
as
begin
declare @ParentID int
set @ParentID=@ID
while @ParentID<>0
begin
insert into @table(ID) select ID from A where ParentID= @ParentID
set @ParentID=(select top 1 ID from @table order by ID desc)
end
return
end

sxiaohui8709253 2010-05-08
  • 打赏
  • 举报
回复
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER function [dbo].[GetAllParents](@ID int)
returns @table table(ID int)
as
begin
declare @ParentID int
set @ParentID=(select ID from A where ParentID= @ID)
while @ParentID!=0
begin
insert into @table(ID) select ID from A where ParentID= @ParentID
set @ParentID=(select top 1 ID from @table order by ID desc)
end
end
sql_lover 2010-05-08
  • 打赏
  • 举报
回复
--return @table
blueclair 2010-05-08
  • 打赏
  • 举报
回复
正在学习ing

34,590

社区成员

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

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