2017-03-10 7 views
0

Simba의 ODBC SFDC 드라이버를 사용하여이 쿼리를 실행하려고했으나 로그에 case 문 근처에 오류가 표시됩니다. 나는 CASE 문에 대한 오류를 완전히 확신하지는 않지만 내 오류가 어디에 있는지 알지 못합니다. 누군가 제발 도와주세요 !!!!CASE 문의 SQL 쿼리 오류?

SELECT 
    Account_Group__c, 
    Hospital_Sales_Teammate__c, 
    Name, 
    StageName, 
    CloseDate, 
    Yr_Credited__c, 
    Probability, 
    Census__c, 
    Credit__c, 
    Related_VSA__c, 
    AB_Hospital_Relationship_Type__c, 

CASE 
    WHEN Age_In_Stage__c >0 and Age_In_Stage__c <= 30 THEN '<30' 
    WHEN Age_In_Stage__c >30 and Age_In_Stage__c <= 60 THEN '31-60' 
    WHEN Age_In_Stage__c >60 and Age_In_Stage__c <= 90 THEN '61-90' 
     ELSE '>90' END AS Age_Bucket, 

CASE 
    WHEN (Type = "Existing Business - Renewal" OR Type = 'Existing Business - Amendment') 
     AND (Account_HHV_Segment__c='A' OR Account_HHV_Segment__c='B') 
     AND AB_Hospital_Relationship_Type__c<>'N/A' 
     AND (RecordType='PWuAAM' 
     OR RecordType='01250000000DcJkAAK' 
     OR RecordType='01250000000DpV4AAK' 
     OR RecordType='01250000000Dxd7AAC' 
     OR RecordType='01250000000DoFPAA0' 
     OR RecordType='01250000000DuuEAAS') THEN 'Hosp' 
    WHEN Name LIKE '%AB Hospital Loss%' THEN 'Hosp' 
     ELSE '' END AS Hospital_Eligible, 

CASE 
    WHEN RecordType='01250000000DpV4AAK' 
     AND Type LIKE '%Acquisition%' 
    THEN 'Acq' 
     ELSE '' END AS Acquisition_Eligible, 

CASE 
    WHEN RecordType='01250000000Dxd7AAC' 
     AND (Business_Unit__c="Full Conversion" OR Business_Unit__c="Partial Conversion") 
    THEN 'BGC' 
     ELSE '' END AS Conversion_Eligible, 

CASE 
    WHEN RecordType='01250000000DuuEAAS' 
     AND Type_of_Agreement__c ="MDA" OR Type_of_Agreement__c ="Joinder" OR Type_of_Agreement__c ="JV" 
    THEN 'Incr Doc' 
     ELSE '' END AS Incr_Doc_Eligible 

FROM 
Opportunity 

WHERE 
    Eligible__c<>'No' 
AND NOT Name LIKE '%test%' 
AND NOT Name LIKE '%Test%' 
AND NOT Name LIKE '%TEST%' 

ORDER BY 
Account_Group__c ASC 
+0

오류가 무엇으로 변경해야합니까? –

답변

1

Business_Unit__c="Full Conversion" (뿐만 아니라 다른 장소) : 당신은 대신 작은 따옴표 큰 따옴표를 사용하는 (당신은 쿼리의 나머지 부분에서처럼). 그게 문제라고 생각해.

또한 이것은 진술이 아니라 사례 표현입니다.

+0

좋은 지적. 이중 따옴표를 제거하고 그 첫 번째 사례 식에서 여전히 오류를 배치합니다. Simba의 문제는 오류가 어디서 무엇인지 또는 오류가 무엇인지 정확히 알려주지 않는다는 것입니다. 생각? – sqlbg

+0

'Age_In_Stage__c'가'integer'가 아닌 한, 지금 다른 오류는 보이지 않습니다. 더 이상 오류가 없을 때까지 사례 표현을 삭제하는 것이 좋습니다. 오류가 어디 있는지 아는 것보다 _what_ 오류가 – HoneyBadger

-1

오류를 잡으려고 시도하십시오.

BEGIN TRY 
    -- RAISERROR with severity 11-18 will cause execution to 
    -- jump to the CATCH block. 
    --RAISERROR ('Error raised in TRY block.', -- Message text. 
    --   16, -- Severity. 
    --   1 -- State. 
    --   ); 


SELECT 
    Account_Group__c, 
    Hospital_Sales_Teammate__c, 
    Name, 
    StageName, 
    CloseDate, 
    Yr_Credited__c, 
    Probability, 
    Census__c, 
    Credit__c, 
    Related_VSA__c, 
    AB_Hospital_Relationship_Type__c, 

CASE 
    WHEN Age_In_Stage__c >0 and Age_In_Stage__c <= 30 THEN '<30' 
    WHEN Age_In_Stage__c >30 and Age_In_Stage__c <= 60 THEN '31-60' 
    WHEN Age_In_Stage__c >60 and Age_In_Stage__c <= 90 THEN '61-90' 
     ELSE '>90' END AS Age_Bucket, 

CASE 
    WHEN (Type = "Existing Business - Renewal" OR Type = 'Existing Business - Amendment') 
     AND (Account_HHV_Segment__c='A' OR Account_HHV_Segment__c='B') 
     AND AB_Hospital_Relationship_Type__c<>'N/A' 
     AND (RecordType='PWuAAM' 
     OR RecordType='01250000000DcJkAAK' 
     OR RecordType='01250000000DpV4AAK' 
     OR RecordType='01250000000Dxd7AAC' 
     OR RecordType='01250000000DoFPAA0' 
     OR RecordType='01250000000DuuEAAS') THEN 'Hosp' 
    WHEN Name LIKE '%AB Hospital Loss%' THEN 'Hosp' 
     ELSE '' END AS Hospital_Eligible, 

CASE 
    WHEN RecordType='01250000000DpV4AAK' 
     AND Type LIKE '%Acquisition%' 
    THEN 'Acq' 
     ELSE '' END AS Acquisition_Eligible, 

CASE 
    WHEN RecordType='01250000000Dxd7AAC' 
     AND (Business_Unit__c="Full Conversion" OR Business_Unit__c="Partial Conversion") 
    THEN 'BGC' 
     ELSE '' END AS Conversion_Eligible, 

CASE 
    WHEN RecordType='01250000000DuuEAAS' 
     AND Type_of_Agreement__c ="MDA" OR Type_of_Agreement__c ="Joinder" OR Type_of_Agreement__c ="JV" 
    THEN 'Incr Doc' 
     ELSE '' END AS Incr_Doc_Eligible 

FROM 
Opportunity 

WHERE 
    Eligible__c<>'No' 
AND NOT Name LIKE '%test%' 
AND NOT Name LIKE '%Test%' 
AND NOT Name LIKE '%TEST%' 

ORDER BY 
Account_Group__c ASC 

END TRY 
BEGIN CATCH 
    DECLARE @ErrorMessage NVARCHAR(4000); 
    DECLARE @ErrorSeverity INT; 
    DECLARE @ErrorState INT; 

    SET @ErrorMessage = ERROR_MESSAGE(); 
    SET @ErrorSeverity = ERROR_SEVERITY(); 
    SET @ErrorState = ERROR_STATE(); 

    -- Use RAISERROR inside the CATCH block to return error 
    -- information about the original error that caused 
    -- execution to jump to the CATCH block. 
    RAISERROR (@ErrorMessage, -- Message text. 
       @ErrorSeverity, -- Severity. 
       @ErrorState -- State. 
       ); 
END CATCH; 
+0

입니다. – HoneyBadger

+0

및 Simba의 SFDC 드라이버가 BEGIN TRY를 지원하지 않지만 실제로는 해결책이 아닙니다 – sqlbg

0

왜 큰 따옴표를 사용하고 있습니까?

(Type = "Existing Business - Renewal" OR Type = 'Existing Business - Amendment')

당신은

(Type = 'Existing Business - Renewal' OR Type = 'Existing Business - Amendment') 
+0

큰 따옴표를 제거했으며 계속 배치했습니다. 첫 번째 case 표현식에서의 오류. Simba의 문제는 오류가 어디서 무엇인지 또는 오류가 무엇인지 정확히 알려주지 않는다는 것입니다. – sqlbg