请问这sql哪里有错?在线等,谢谢
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
alter FUNCTION [dbo].[GetChildId](@ClassId int)
RETURNS table
AS
--定义变量@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
消息 156,级别 15,状态 1,过程 GetChildId,第 5 行
关键字 'declare' 附近有语法错误。
[解决办法]
Declare table_sursor Cursor for Select LastNode from Class where ParentId =@ClassId -->Declare table_sursor Cursor LOCAL STATICREAD_ONLYfor 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 那个表