CREATE VIEW pal_vCampaignDetail
AS
SELECT	C.recId ,
        C.campaignTitle ,
        C.campaignBody ,
        C.campaignType campaignTypeId ,
        C.isRecurring ,
        C.interval intervalId ,
        C.messageType ,
        C.lastSent ,
        C.nextSend ,
        C.createdBy ,
        C.dateSaved ,
        C.dateUpdated ,
        C.isActive ,
        C.isDraft ,
        C.contactSourceSurface ,
        C.contactNumberField ,
        C.contactNameField ,
        C.filterField ,
        C.filterValue ,
        I.interval ,
		T.campaignType
FROM	dbo.pal_Campaign C
		JOIN dbo.pal_CampaignInterval I
			ON I.recId = C.interval
		JOIN dbo.pal_CampaignType T
			ON T.recId = C.campaignType
WHERE	T.campaignType <> 'Ad Hoc'
		OR (T.campaignType = 'Ad Hoc' AND C.isDraft = 1)