这有点令人困惑,因为它之前工作过,我添加了 1 个小改动,我在我的 Web 应用程序中收到了这个错误消息。(我确实有其他案例,为简单起见,我只是取出了其他案例)
之前工作的原始代码:
ALTER PROCEDURE [dbo].[GetRoles]
(@reportid Decimal, @dom varchar(10))
AS
DECLARE @sql varchar(2000)
SELECT @sql =
Case @reportid
WHEN 1 THEN
'select u.id as userId, u.domain, u.isAdmin, u.email, u.canReport, a.[site], a.bldgNum, a.dataCenterNum, l.shortName, l.[description], a.canApprove, a.canComplete
from locAdmin a
inner join location l on (a.site=l.site and a.bldgNum = l.bldgNum and a.dataCenterNum = l.dataCenterNum)
right outer join [user] u on u.id=a.userId and u.domain=a.domain
where u.isAdmin = 1'
End
EXEC (@sql)
我做的唯一改变是添加
and u.domain = @dom'
在最后的 u.isAdmin = 1' 之后,看起来像这样
where u.isAdmin = 1 and u.domain = @dom'