我正在應用一個查詢,我需要爲單個部門或所有部門獲取結果。應用案例從SQL中獲取所有記錄
PersonID PersonName
1 'Abc'
2 'CDE'
3 'xyz'
DepartmentID DepartmentName
1 'Accounts'
2 'Finance'
HirarchyID personID DepartmentID
1 1 1
2 1 1
3 2 1
現在我想在我的SQL查詢我有過爲1 = 'Accounts', 2='Finance' and 0 = 'Both'
我怎麼會在我的查詢應用此@department參數的參數?
我嘗試申請與案件,但它只會讓我或者帳戶或財務..但不是兩個。
select * from persons p join
Hierarchy h on h.PersonID = p.PersonID JOIN
Department d on d.DepartmentID = h.DepartmentID
where case ???
我的樣品凡在我查詢子句是這樣的:
WHERE (sa.Area in (case when @myMode = 1 THEN 'abc Mode'
when @myMode = 2 THEN 'XYZ Mode'
ELSE
'abc Mode,xyz Mode'
END))
地方是查詢:
相反,如果你希望所有的部門,如下更改此行的代碼? – Jade
這只是我試圖達到的一個例子..我的查詢是相當複雜的,有一個where子句,我需要應用這種情況 – Moiz