set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
alter FUNCTION [dbo].[GetChildId](@ClassId int)
RETURNS table
AS
[email protected]
declare @LastNode int 提示这里有错
--定义游标,
Declare table_sursor Cursor for Select LastNode from Class where ParentId [email protected]
--打开游标
open table_sursor
--提取第一行记录,[email protected]
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 [email protected]
end
Fetch next from table_sursor into @LastNode
end
消息 156,级别 15,状态 1,过程 GetChildId,第 5 行
关键字 'declare' 附近有语法错误。
------解决方案--------------------
- SQL code
Declare table_sursor Cursor for Select LastNode from Class where ParentId [email protected] -->Declare table_sursor Cursor LOCAL STATICREAD_ONLYfor Select LastNode from Class where ParentId [email protected]
------解决方案--------------------
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
alter FUNCTION [dbo].[GetChildId](@ClassId int)
RETURNS table
AS
begin
[email protected]
declare @LastNode int 提示这里有错
--定义游标,
Declare table_sursor Cursor for Select LastNode from Class where ParentId [email protected]
--打开游标
open table_sursor
--提取第一行记录,[email protected]
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 [email protected]
end
Fetch next from table_sursor into @LastNode
end
close table_sursor
deallocate table_sursor
end
------解决方案--------------------
呵呵,少了
begin
end
------解决方案--------------------
函数不能 select 返回数据,应该定义table变量,然后插入数据,然后return 那个表