如您所见,我有一个选择多个字段的视图。查询的主要焦点是 xro_roles.start_page。此字段包含一个起始页链接,供存储过程参考。但我有第二张表也包含一些链接(这个表称为分支)。如果 dbo.people.role_id = 1 那么我需要它来使用分支表作为 start_page 列。如果 role_id 不是 1,那么它应该引用 xro_roles.start_page。
我不确定在这种情况下如何使用 CASE 语句。如果我没有提供足够的信息,请告诉我。
谢谢
SELECT dbo.people.people_id, dbo.people.role_id, dbo.people.company_id,
dbo.xro_roles.start_page, dbo.areas.area_id,
FROM dbo.areas RIGHT OUTER JOIN
dbo.divisions ON dbo.areas.area_id = dbo.divisions.area_id RIGHT OUTER JOIN
dbo.people LEFT OUTER JOIN
dbo.xro_roles ON dbo.people.role_id = dbo.xro_roles.role_id ON dbo.divisions.division_id = dbo.people.division_id LEFT OUTER JOIN
dbo.companies ON dbo.people.company_id = dbo.companies.company_id LEFT OUTER JOIN
dbo.xro_time_zones ON dbo.people.time_zone_id = dbo.xro_time_zones.time_zone_id
LEFT OUTER JOIN dbo.branches ON dbo.branches.branch_id = dbo.people.division_id
WHERE (dbo.people.status_id IN (0, 1, 4))