1
我試圖使用嵌套大小寫,但是SQL在給出10個限制時給我一個錯誤。以下是我的SQL。你有什麼建議嗎?嵌套的大小寫限制
ALTER VIEW [dbo].[vwOpti_ChannelPreference] AS
SELECT SUB.*,
CASE WHEN PCYCResponse + JBIResponse > 1 THEN 'SF Multi'
ELSE CASE WHEN MDLResponse + SermoResponse + BioPharmResponse + MedscapeResponse + PharmaConnectResponse + THResponse
+ OtherResponse > 1 THEN 'MCM Multi'
ELSE CASE WHEN MDLResponse + SermoResponse + BioPharmResponse + MedscapeResponse + PharmaConnectResponse + THResponse
+ PCYCResponse + JBIResponse + OtherResponse > 1 THEN 'SF & MCM Multi'
ELSE CASE WHEN MDLResponse + SermoResponse + BioPharmResponse + MedscapeResponse + PharmaConnectResponse + THResponse
+ PCYCResponse + JBIResponse + OtherResponse = 0 THEN 'None'
ELSE CASE WHEN MDLResponse = 1 THEN 'MDL'
ELSE CASE WHEN SermoResponse = 1 THEN 'Sermo'
ELSE CASE WHEN BioPharmResponse = 1 THEN 'BioPharmCommunications'
ELSE CASE WHEN MedscapeResponse = 1 THEN 'Medscape'
ELSE CASE WHEN PharmaConnectResponse = 1 THEN 'PharmaConnect'
ELSE CASE WHEN THResponse = 1 THEN 'Targeted Healthcare'
ELSE CASE WHEN PCYCResponse = 1 THEN 'PCYC'
ELSE CASE WHEN JBIResponse = 1 THEN 'JBI'
ELSE CASE WHEN OtherResponse = 1 THEN 'Other'
END END END END END END END END END END END END AS ChannelPref
FROM ( SELECT CC.*,
MAX(CASE WHEN MTE.DesignVendor = 'MDL' THEN 1 ELSE 0 END) AS MDLResponse,
MAX(CASE WHEN MTE.DesignVendor = 'Sermo' THEN 1 ELSE 0 END) AS SermoResponse,
MAX(CASE WHEN MTE.DesignVendor = 'BioPharmCommunications' THEN 1 ELSE 0 END) AS BioPharmResponse,
MAX(CASE WHEN MTE.DesignVendor = 'Medscape' THEN 1 ELSE 0 END) AS MedscapeResponse,
MAX(CASE WHEN MTE.DesignVendor = 'PharmaConnect' THEN 1 ELSE 0 END) AS PharmaConnectResponse,
MAX(CASE WHEN MTE.DesignVendor = 'Targeted Healthcare' THEN 1 ELSE 0 END) AS THResponse,
MAX(CASE WHEN MTE.DesignVendor = 'PCYC' THEN 1 ELSE 0 END) AS PCYCResponse,
MAX(CASE WHEN MTE.DesignVendor = 'JBI' THEN 1 ELSE 0 END) AS JBIResponse,
MAX(CASE WHEN MTE.DesignVendor NOT IN ('MDL','Sermo', 'BioPharmCommunications', 'Medscape', 'PharmaConnect',
'Targeted Healthcare', 'PCYC', 'JBI') THEN 1 ELSE 0 END) AS OtherResponse
--SELECT DISTINCT MTE.CHANNELNAME
FROM slice_CampaignContact CC
--LEFT JOIN slice_MktgTactic MTI ON I.MktgTacticID = MTI.MktgTacticID AND I.SliceDate = MTI.SliceDate
LEFT JOIN slice_Engagements E ON CC.ContactID = E.ContactID AND CC.SliceDate = E.SliceDate
LEFT JOIN slice_MktgTactic MTE ON E.MktgTacticID = MTE.MktgTacticID AND E.SliceDate = MTE.SliceDate
GROUP BY CC.SliceDate, CC.BrandCd, CC.ContactID, CC.SyncID, CC.FirstName, CC.LastName, CC.CampaignName,
ClientSegment, ControlSegmentName) SUB
謝謝你,工作得很好。 – Anu
@Anu - 如果這解決了您的問題,請單擊左側的複選標記。 – Hogan