當我在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