我有一个USERS
包含两列 ( RID
, USERNAME
) 的表,我只是通过RID
获取USERNAME
。
我将传递 4 个参数作为 User1、User2、User3、User4RID
现在我想要如下结果:
Level1User Level2User Level3User Level4User
ABC DEF GHI JKL
我试过以下查询:
SELECT
L1.USERNAME AS Level1User,
L2.USERNAME AS Level2User,
L3.USERNAME AS Level3User,
L4.USERNAME AS Level4User
FROM [USERS] AS L1,
[USERS] AS L2,
[USERS] AS L3,
[USERS] AS L4
WHERE L1.RID = @User1RID AND L2.RID = @User2RID AND L3.RID = @User3RID
AND L4.RID = @User4RID
它工作正常,但是当我通过NULL
任何 USER's时它失败了RID
。我不知道该怎么做。