Incorrect syntax near the keyword 'with'.

后端 未结 3 1942
清酒与你
清酒与你 2021-01-17 11:04

Hello I\'m trying to figure out why switching my compatability mode from 80 to 100 in MSSQL broke my function below?

    Microsoft SQL Server 2008 R2 (RTM)         


        
3条回答
  •  星月不相逢
    2021-01-17 11:25

    Add a semicolon before WITH:

    ;with results as
        (
            select parentouid,net_ouid from net_ou where net_ouid=@Param1
            union all
            select t2.parentouid,t2.net_ouid from net_ou t2 
            inner join results t1 on t1.parentouid = t2.net_ouid where t2.parentouid <> t1.net_ouid
        )   
        select @ReturnValue = net_ou.displayname 
        from  NET_OU RIGHT OUTER JOIN
        results ON net_ou.net_ouid = results.ParentouID where results.parentouid=results.net_ouid
    
        RETURN @ReturnValue
    
    END
    

    CTE declarations need to be the first command in the batch.

提交回复
热议问题