是否可以重写此SQL代码?
在这种情况下,用户被分配到多个角色。我希望所有Arrangemang
ID
用户在一个列表中拥有不同的角色。
我想在这些行中重构硬编码的@rollx
......
(kk_aj_tbl_Arrangemang.KonstformID = @roll1) OR
如果可能的话?
以下是我现有的代码......
SELECT kk_aj_tbl_Arrangemang.ArrID,
kk_aj_tbl_Arrangemang.Datum,
(SELECT TOP (1) kk_aj_tbl_content.Rubrik
FROM kk_aj_tbl_content
INNER JOIN kk_aj_tbl_arridtoContent ON kk_aj_tbl_content.Contentid = kk_aj_tbl_arridtoContent.contentid
WHERE (kk_aj_tbl_arridtoContent.arrid = kk_aj_tbl_Arrangemang.ArrID AND
kk_aj_tbl_arridtoContent.Version = 1
)
) AS Rubrik,
(SELECT TOP (1) kk_aj_tbl_content_1.Underrubrik
FROM kk_aj_tbl_content AS kk_aj_tbl_content_1
INNER JOIN kk_aj_tbl_arridtoContent AS kk_aj_tbl_arridtoContent_1 ON kk_aj_tbl_content_1.Contentid = kk_aj_tbl_arridtoContent_1.contentid
WHERE (kk_aj_tbl_arridtoContent_1.arrid = k_aj_tbl_Arrangemang.ArrID AND
kk_aj_tbl_arridtoContent_1.Version = 1
)
) AS UnderRubrik,
kk_aj_tbl_Arrangemang.Publicerad,
kk_aj_tbl_Arrangemang.LookedAt,
kk_aj_tbl_ArrangemangStatus.ArrangemangStatus,
kk_aj_tbl_Arrangemangtyp.arrangemangtyp,
kk_aj_tbl_Konstformtyp.konstform,
kk_aj_tbl_utovare.Organisation,
Users.Username
FROM kk_aj_tbl_Arrangemang
INNER JOIN kk_aj_tbl_utovare ON kk_aj_tbl_Arrangemang.UtovarID = kk_aj_tbl_utovare.UtovarID
INNER JOIN kk_aj_tbl_ArrangemangStatus ON kk_aj_tbl_Arrangemang.ArrangemangStatusID = kk_aj_tbl_ArrangemangStatus.ArrangemangStatusID
INNER JOIN kk_aj_tbl_Konstformtyp ON kk_aj_tbl_Arrangemang.KonstformID = kk_aj_tbl_Konstformtyp.KonstformID
INNER JOIN kk_aj_tbl_Arrangemangtyp ON kk_aj_tbl_Arrangemang.ArrangemangstypID = kk_aj_tbl_Arrangemangtyp.ArrangemangstypID
INNER JOIN Users ON kk_aj_tbl_Arrangemang.AdminuserID = Users.UserID
WHERE (kk_aj_tbl_ArrangemangStatus.ArrangemangStatusID = @arrStatusTyp)
AND (kk_aj_tbl_Arrangemang.VisningsPeriod = @visningsperiod)
AND ((kk_aj_tbl_Arrangemang.KonstformID = @roll1) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll2) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll3) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll4) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll5) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll6) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll7) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll8) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll9) OR
(kk_aj_tbl_Arrangemang.KonstformID = @roll10)
)
答案 0 :(得分:0)
我认为您可能正在寻找IN
运营商:
...AND kk_aj_tbl_Arrangemang.KonstformID IN (@roll1, @roll2, ...@rolln)