我需要一些幫助來將附加列中的'comment'和帶有where子句的select語句一起添加。選擇帶有where子句的語句並在另一列中添加'comment'
當前代碼
首先聲明
SELECT * FROM [Table] WHERE [Dep] = 'M' AND
([Join M] <> [Join B] OR
[Resign M] <> [Resign Date Beneficiary])
GO
第二條語句
SELECT * FROM [Table] WHERE [Join B] < [Resign B] AND
([Join M] > [Join B] OR
[Resign M] < [Resign B])
GO
這是兩個不同的select語句,但是我想兩個輸出組合成一張桌子。
錯誤的代碼 - (例子來解釋)
首先聲明
SELECT * FROM [Table] WHERE [Dep] = 'M' AND
([Join M] <> [Join B] OR
[Resign M] <> [Resign Date Beneficiary])
SET AS [Comment] = 'Main'
GO
第二條語句
SELECT * FROM [Table] WHERE [Join B] < [Resign B] AND
([Join M] > [Join B] OR
[Resign M] < [Resign B])
SET AS [Comment] = 'Date'
GO
的要求是一個額外的列添加到輸出並添加'評論'在現場,也可以將兩個輸出結合在一個表格中。
輸出
首先聲明輸出
[Number] |[Dep] |[Join M] |[Join B] |[Resign M ]|[Resign B]
10003 |M |20160101 |20160201 |20160301 |20160301
10004 |M |20160101 |20160201 |20160301 |20160401
第二條語句輸出
[Number] |[Dep] |[Join M] |[Join B] |[Resign M ]|[Resign B]
10000 |M |20160201 |20160201 |20160131 |20160430
10002 |M |20160501 |20160430 |20160430 |20160430
所需的輸出
[Number] |[Dep] |[Join M] |[Join B] |[Resign M ]|[Resign B]|[Comment]
10000 |M |20160201 |20160201 |20160131 |20160430 |'Date'
10002 |M |20160501 |20160430 |20160430 |20160430 |'Date'
10003 |M |20160101 |20160201 |20160301 |20160301 |'Main'
10003 |M |20160101 |20160201 |20160301 |20160401 |'Main'
謝謝你兩個答案之間的聯盟,他們都是相同的,我需要的準確輸出。謝謝。 –