【发布时间】:2015-02-03 23:11:43
【问题描述】:
我想根据列值连接两个表
- 如果
pm.ServiceLevelID的值为1 或NULL,则在u.FacilityId上进行内连接 - 如果
pm.ServiceLevelID的值为2,则在u.FacilityServiceId上进行内连接
pm, u 这两个表有这些列:
ProviderMessages
MessageID, FacilityServiceID, ServiceLevelID, FacilityID, ProviderTypeID
User_FA
FacilityServiceId, UserFacilityID, FacilityId
目前,我有这个INNER JOIN
SELECT DISTINCT
MessageID, UserFacilityID, 9
FROM
#ProviderMessages
INNER JOIN
#User_FA ON (#User_FA.FacilityId = #ProviderMessages.FacilityID OR
#ProviderMessages.FacilityID IS NULL)
AND (#User_FA.FacilityServiceId = #ProviderMessages.FacilityServiceID)
【问题讨论】:
-
使用Case
-
我想知道这个问题有什么不好。 -5,真的吗?
标签: sql sql-server sql-server-2008 tsql inner-join