create function f_getGrop()
returns table 
as 
  begin
  declare @re table 
  set @re=(select * from selfcheck s where not exists(select idxnum from selfcheck where idxnum=(select parentid from indexs where idxnum=s.idxnum)))
  return(select pid,sum(selfReal) from @re )
go
错误:服务器: 消息 156,级别 15,状态 1,过程 f_getGrop,行 6
在关键字 'set' 附近有语法错误。
服务器: 消息 137,级别 15,状态 1,过程 f_getGrop,行 7
必须声明变量 '@re'。
服务器: 消息 170,级别 15,状态 1,过程 f_getGrop,行 7
第 7 行: ')' 附近有语法错误。
请高手帮忙看一下

解决方案 »

  1.   

    create function f_getGrop()
    returns table 
    as 
    return (select pid,sum(selfReal) from selfcheck s where not exists
    (select 1 from selfcheck where idxnum=(select parentid from indexs where idxnum=s.idxnum))
    group by pid)
    GO
      

  2.   

    declare @re table (字段1 类型,字段2 类型,...)
    ------------------------这个地方既然是声明一个表变量,那么后面一点要加上表内定义的字段
      

  3.   

    --trycreate function dbo.f_getGrop()
    returns table 
    as return
    (
    select 
            pid,
            sum(selfReal) as selfReal
    from (
            select * 
            from selfcheck s 
            where not exists(select idxnum from selfcheck where idxnum=(select parentid from indexs where idxnum=s.idxnum))
    ) as T
    group by pid)
    go
      

  4.   


    create function f_getGrop()
    returns table 
    as 
      begin  return(select pid,sum(selfReal) from (select * from selfcheck s where not exists(select idxnum from selfcheck where idxnum=(select parentid from indexs where idxnum=s.idxnum))) v )
    end 
      

  5.   

    wangtiecheng您的可以用了,谢谢!结贴给分。hellowork的有错误