2009-10-19 5 views
0
select 
(distributor_code+ '-' +master_dealer_code+ '-' +state_code+ '-' +dealer_code) as agent_code, 
agent_type, company,contact_person, status, created_date as date, 
(CASE 
WHEN contact_mobile_no IS NOT NULL THEN contact_mobile_no 
WHEN contact_mobile_no IS NULL and contact_office_no IS NOT NULL THEN contact_office_no 
ELSE NULL 
END) as contact_no 

from sdms_agent 

where agent_type ='{?AgentType}' and status ='{?Status}' 

order by (distributor_code+ '-' +master_dealer_code+ '-' +state_code+ '-' +dealer_code) 

실제로 크리스탈 보고서에 두 개의 매개 변수를 설정하고 싶습니다. agent_type (Main, DIstributor, Master Dealer, Dealer) & 상태 (활성, 부호 없음, 종료, 일시 중단).수정 보고서에 2 가지 다른 매개 변수를 지정하는 방법은 무엇입니까?

나는 실제로 매개 변수를 얻는다. 그러나 agent_type 또는 status를 선택할 때 보고서에서 하나씩 선택하여 볼 수 있습니다. 예 : agent_type에 대해 Distributor를 선택하고 상태를 Active로 선택합니다. 그것에 대한 올바른 보고서가 나오게 될 것입니다.

하지만 지금은 모든 상태로 배포자를보고 싶습니다. 하지만 '% e %'를 넣었지만 작동하지 않습니다. 결과가 나오지 않습니다. 상태가 다른 분배자를 포함하는 목록을 원하거나 하나의 상태를 가진 다른 agent_type을 원하거나 보고서에서 모두보기를 원합니다.

답변

1

내가 처리 할 수있는 가장 쉬운 방법은 선택 전문가의 수식에 switch 문을 사용하는 것입니다.

select (distributor_code+ '-' +master_dealer_code+ '-' +state_code+ '-' +dealer_code)as agent_code , agent_type, company,contact_person, status, created_date as date, (CASE WHEN contact_mobile_no IS NOT NULL THEN contact_mobile_no WHEN contact_mobile_no IS NULL and contact_office_no IS NOT NULL THEN contact_office_no ELSE NULL END)as contact_no 
from sdms_agent 
where agent_type = case @AgentType when '' then agent_type else @AgentType end 
and status = case @Status when -1 then status else @Status end 
order by (distributor_code+ '-' +master_dealer_code+ '-' +state_code+ '-' +dealer_code) 
:

switch ( 
{?AgentType} = "Distributor", {table1;1.agent_type} = "Distributor", 
{?AgentType} = "Other", {table1;1.agent_type} = "other", 
true, true 
) 

것은 그런 다음 더 나은 방법은 다음과 같은 뭔가 쿼리에서 그것을 처리하는 것입니다 SQL 서버를 사용하는 경우 : 당신이 뭔가를 할 수이 예에서

쿼리에서 모든 AgentTypes를 표시하려면 빈 문자열을 전달하고 모든 상태를 표시하려면 -1을 쿼리에 전달합니다.

희망이 있습니다.

관련 문제