我有这个Oracle查询:
SELECT company, structure_id, team_code
FROM structure_main_tab
WHERE (company, parent_structure_id, team_code)
IN (SELECT company, structure_id, team_code
FROM structure_main_tab
WHERE (company, parent_structure_id, team_code)
IN (SELECT company, structure_id, team_code
FROM company_user_tab
WHERE UPPER(fusername) = UPPER('xxx') AND fdeleted = 'N'
)
);
我正在尝试将此oracle查询转换为SQL Server查询。
有人可以帮我吗?
答案 0 :(得分:1)
尝试以下查询:
SELECT company, structure_id, team_code into #temp1
FROM company_user_tab
WHERE UPPER(fusername) = UPPER('xxx') AND fdeleted = 'N'
SELECT company, structure_id, team_code
FROM structure_main_tab Mt inner join #temp1 tt
on Mt.company=tt.company and mt.parent_structure_id=tt.structure_id
and mt.team_code=tt.team_code
答案 1 :(得分:1)
认为您不能在Sql Server中为IN子句使用多个列。
我会用exists子句和连接替换
SELECT company, structure_id, team_code
FROM structure_main_tab smt
WHERE EXISTS (select null from
structure_main_tab smt1
join company_user_tab cut on cut.company = smt1.company and
cut.structure_id = smt1.parent_structure_id and
cut.team_code = smt1.team_code
where UPPER(cut.fusername) = UPPER('xxx') AND cut.fdeleted = 'N'
and smt.company = smt1.company
and smt.parent_structure_id = smt1.structure_id
and smt.team_code = smt1.team_code)