我在如何排序下面的聯合查詢的第二個選擇語句中的數據丟失。與聯盟和空值排序SQL Server
的期望的結果將是:
C null null null null null
I xxxx xxxx xxxx 1 xxxx
I xxxx xxxx xxxx 1 xxxx
I xxxx xxxx xxxx null xxxx
I xxxx xxxx xxxx null xxxx
下面是代碼:
select 'C' [Identifier]
,null [Acct/Invoice #]
,null [Check #/Pay Amount]
,null [Check Amount/Error Code]
,null [Error Flag]
,null [Trx Account #]
union all
select 'I' [Indentifer]
,final_inv_number [Invoice #]
,final_final_pay_amount [Pay Amount]
,final_trans_code [Error Code]
,case when final_is_reconciled = 1 then 1 end [Error Flag]
,case when final_parse_type = 'ERROR CREATED' or final_parse_type = 'PREV PD'
then final_account_number else null end [Trx Account #]
from #final
where final_net_pay_amount <> 0
--order by [Error Flag] ?
對於這種情況,這是一個很好的答案,所以+1。我沒有看到'[標識符]'在這裏是一個常量。 – Benoit 2011-12-21 15:52:57
O_o好的,這是我以前想過的*以前我曾嘗試過,並且出現語法錯誤,儘管它現在工作完美:)感謝您的幫助! ...我想這只是其中的一個...... – ChandlerPelhams 2011-12-21 15:56:49