当我在SQL Server上运行下面的查询时,它对单值或多值工作正常。但是当我尝试在SSRS数据集上执行相同的操作时,它将为多个值引发错误。在上下文中指定的非布尔类型的表达式,其中条件接近','
ERROR: SSRS: An expression of non boolean type specified in a context where a condition is expected near ','. Incorrect syntax near the keyword 'ELSE'.
它工作正常,单值。不知道是什么问题,或者有什么其他的方式可以写这个查询。
DECLARE @UserTeam VARCHAR(max) = 'Team1,Team2,Team3,Team4,Team5,Team6,'''
-- Values can inculdes null. if user select blank and Team1,Team2 we need to pull data which is null, Team1, Team2
IF Object_id('tempdb.dbo.#Team', 'U') IS NOT NULL
DROP TABLE #team;
SELECT item AS Team
INTO #team
FROM dbo.FNSPLIT(@UserTeam, ',')
IF @UserTeam = ''
BEGIN
SELECT U.username,
T.teamcode
FROM [User].vwuser u
LEFT JOIN[User].userteam UT
ON U.userid = UT.userid
LEFT JOIN [User].team AS T
ON T.teamid = Ut.teamid
WHERE T.teamcode IS NULL
ORDER BY U.username
END
ELSE
BEGIN
SELECT U.username,
T.teamcode
FROM [User].vwuser u
LEFT JOIN [User].userteam UT
ON U.userid = UT.userid
LEFT JOIN [User].team AS T
ON T.teamid = Ut.teamid
JOIN #team tm
ON T.teamcode = tm.team
WHERE (U.username NOT LIKE '%System%')
ORDER BY U.username
END
是的,我给'来表示为空来解释。因为如果我在SSRS参数中选择空白字段,我不确定它传递的值是多少 – crony