开发者

SQL statement works on one MSSQL database but gives syntax error on another

I am altering a stored procedure. When I make the change, it works fine on my DEV database. However, when I try to alter the stored procedure on another database (QA), I get a syntax error. The statement in the stored procedure that is causing the error is the following:

UPDATE #tmpPeriod 
SET statusDesc = 
    CASE 
        WHEN
            (SELECT count(*) 
            FROM [dbo].[vw_TeamInc开发者_C百科entiveStatus] with (nolock) 
            WHERE 
                [periodEndDate] = #tmpPeriod.periodEndDateF 
                and teamID in (Select teamID From dbo.GetTeamsWithActiveMembers(#tmpPeriod.periodEndDateF)))
            = 
            (SELECT COUNT(*) FROM teamIncentivestatus WHERE periodID = #tmpPeriod.periodID AND status =1)
    THEN 'OPEN - All teams approved.' 
    ELSE
        #tmpPeriod.statusDesc
    END
WHERE statusDesc <> 'OPEN - No productivity.'

The error message is: 'Incorrect syntax near '.'' and occurs on line 9 of the snippet above.

I made sure that the vw_TeamIncentiveStatus view and the GetTeamsWithActiveMembers function are in both databases and are identical.

Any help as to why I get a syntax error on one DB but not the other would be greatly appreciated.


Line 9 in your posted code contains

dbo.GetTeamsWithActiveMembers(#tmpPeriod.periodEndDateF)

The ability to reference columns in TVF calls was not introduced until SQL Server 2005 (came in with the APPLY operator). Do your two databases have different compatibility modes?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜