2017-07-07 6 views
0
select t1.customer_code as doc_num, CONVERT(VARCHAR,t2.created_on,103) as doc_date, 
t2.sap_cardcode as sap_doc_num ,t2.void_flg,t2.status_ind,t2.err_msg 
from customer t1 
inner join sap_customer t2 on t1.id = t2.customer_id 
where t2.status_ind = case when @test = 'todo' then t2.status_ind='1' else t2.status_ind='0' END 

上記は、どこのステートメントを実行する必要があるかを決定するためにパラメータを渡す必要がある、私が行う必要のあるselectステートメントです。 ステータスInd = 1またはステータスInd = 0SQLのcase文はどこですか?

+0

エラーは何ですか? – Ravi

+0

"="付近の構文が正しくない – hunt

+0

WHERE句では、大文字と小文字の区別の代わりにAND/ORを使用する方がよい場合があります。 – jarlh

答えて

3

私はあなたの質問に少し修正しました。

select t1.customer_code as doc_num, CONVERT(VARCHAR,t2.created_on,103) as doc_date,t2.sap_cardcode as sap_doc_num ,t2.void_flg,t2.status_ind,t2.err_msg 
from customer t1 
inner join sap_customer t2 on t1.id = t2.customer_id 
where t2.status_ind = case when @test = 'todo' then '1' else '0' END 

か、以下のような場合に使用することができます:あなたのCASE文はあなたがwhere t2.status_indを比較しようとしている、ので

case when @test = 'todo' then '1' else '0' END 

を変更する必要がある

where t2.status_ind = case @test when 'todo' then '1' else '0' END 
2

をこの情報がお役に立てば幸いです。したがって、設定する代わりにCASEから値を返す必要があります。