日期:2014-05-18 浏览次数:20435 次
Declare table_sursor Cursor for Select LastNode from Class where ParentId =@ClassId --> Declare table_sursor Cursor LOCAL STATIC READ_ONLY for Select LastNode from Class where ParentId =@ClassId
------解决方案--------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
alter FUNCTION [dbo].[GetChildId](@ClassId int)
RETURNS table
AS
begin
--定义变量@LastNode是否是最后一个节点
declare @LastNode int 提示这里有错
--定义游标,
Declare table_sursor Cursor for Select LastNode from Class where ParentId =@ClassId
--打开游标
open table_sursor
--提取第一行记录,赋值给变量@LastNode
Fetch next from table_sursor into @LastNode
--检查@@Fetch_Status以确定是否还可以继续取数
while @@Fetch_Status = 0
begin
if(@LastNode = 1)
begin
SELECT ClassName,ClassId From Class where ParentId =@ClassId
end
Fetch next from table_sursor into @LastNode
end
close table_sursor
deallocate table_sursor
end
------解决方案--------------------
呵呵,少了
begin
end
------解决方案--------------------
函数不能 select 返回数据,应该定义table变量,然后插入数据,然后return 那个表