このクエリを実行していて、上記のエラーが発生することがあります。 メッセージ4145、レベル15、状態1、プロシージャGetQN8、Line 1592 条件が期待されるコンテキストで指定された非ブール型の式で、 'END'の近く。。誰かが私を助けてくれますか?どこが間違っていますか?'END'の近くで条件が期待されるコンテキストで指定された非ブール型の式
これはコードです -
USE [MailActivity]
GO
IF OBJECT_ID('GetQN8') IS NULL
EXEC('CREATE PROCEDURE GetQN8 AS SET NOCOUNT ON;')
GO
ALTER PROCEDURE GetQN8 (@CampaignName VARCHAR(200),@EngagedMonths INT, @Active VARCHAR(10), @NotInGroup INT, @CampaignNameForDupCheck VARCHAR(200))
AS
BEGIN
SET NOCOUNT ON
-- CREATE TEMP TABLES DROP TABLE #tempParticipantDataQN8
CREATE TABLE #tempParticipantDataQN8
(
ParticipantId INT PRIMARY KEY,
GroupId INT,
EmailAddress VARCHAR(200),
FirstName VARCHAR(100),
ActiveYN CHAR(1),
NewsLetterStatus CHAR(1),
ExpirationDate DATETIME
)
-- CREATE INDEX
CREATE NONCLUSTERED INDEX [IX_TempParticipantDataEmail] ON #tempParticipantDataQN8
(
[EmailAddress] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
-- DROP TABLE #tempParticipantAuditDataQN8
CREATE TABLE #tempParticipantAuditDataQN8
(
ParticipantId INT,
ColumnName VARCHAR(100),
AfterChangeValue VARCHAR(100),
LastChangedDate DATETIME,
LastChangedUser VARCHAR(100)
)
-- CREATE INDEX
CREATE NONCLUSTERED INDEX [IX_TempParticipantAuditDataColumnName] ON #tempParticipantAuditDataQN8
(
[ColumnName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [IX_TempParticipantAuditDataPartId] ON #tempParticipantAuditDataQN8
(
[ParticipantId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
INSERT INTO #tempParticipantDataQN8 (ParticipantId,EmailAddress,FirstName,ActiveYN,NewsLetterStatus,GroupId,ExpirationDate)
SELECT p.ParticipantId,
p.[Preferred Email],
p.[First Name],
p.ActiveYN,
p.NewsLetterStatus,
p.GroupId,
p.expirationdate
FROM ids_reporting.ids_reporting.dbo.Participant p WITH (NOLOCK)
JOIN ids_reporting.ids_reporting.dbo.[Group] gr WITH (NOLOCK)
ON p.groupId = gr.groupId
WHERE 1=1
AND ((p.[Preferred Email] NOT LIKE '%@none.com') AND (p.[Preferred Email] IS NOT NULL)) -- Has an email address
AND ISNULL(gr.parentGroupId,'') <> 1269
-- PULL AUDIT
INSERT INTO #tempParticipantAuditDataQN8 ( ParticipantId, ColumnName, AfterChangeValue, LastChangedDate, LastChangedUser)
SELECT a.ParticipantId, ColumnName, AfterChangeValue, LastChangedDate, LastChangedUser
FROM ids_reporting.ids_reporting.dbo.Participant_Audit a
JOIN #tempParticipantDataQN8 p
ON p.ParticipantId = a.ParticipantId
AND a.ColumnName = 'NewsLetterStatus'
AND a.AfterChangeValue = 'U'
--Query
SELECT DISTINCT(p.[EmailAddress]) AS [EmailAddress],
p.FirstName AS [FirstName],
p.GroupId AS [GroupId]
FROM [CampaignLists],#tempParticipantDataQN8 p
LEFT OUTER JOIN MailActivity.dbo.SupressionList08012016 sup
ON p.[EmailAddress] = sup.EmailAddress
JOIN MailActivity.dbo.MailActivities maEng WITH (NOLOCK)
ON (p.[EmailAddress] = maEng.EmailAddress
AND maEng.EventType = 'MessageGears.Model.Generated.OpenActivity'
AND maEng.EventTimestamp >= DATEADD(month, @EngagedMonths, GETDATE())
)
LEFT OUTER JOIN
(
SELECT DISTINCT(EmailAddress) AS [EmailAddress]
FROM MailActivity.dbo.MailActivities WITH (NOLOCK)
WHERE EventType = 'MessageGears.Model.Generated.BouncedActivity'
AND CategoryCode NOT IN ('10', '30')
GROUP BY EmailAddress
HAVING COUNT(*) >= 3
) AS SoftBounce
ON p.[EmailAddress] = SoftBounce.EmailAddress
LEFT OUTER JOIN MailActivity.dbo.MailActivities spam WITH (NOLOCK)
ON (p.[EmailAddress] = spam.EmailAddress
AND spam.EventType IN ('MessageGears.Model.Generated.UnsubActivity', 'MessageGears.Model.Generated.SpamComplaintActivity'))
WHERE 1=1
AND SoftBounce.EmailAddress IS NULL -- No soft bounces >= 3
AND spam.EmailAddress IS NULL -- No spam complaints
AND sup.EmailAddress IS NULL -- No suppression list
AND p.ActiveYN = @Active
AND [CampaignLists].CampaignName = @CampaignName
AND ((p.[EmailAddress] NOT LIKE '%@none.com') AND (p.[EmailAddress] IS NOT NULL)) -- Has an email address
AND p.GroupId NOT IN (@NotInGroup)
AND NOT EXISTS (SELECT 1 FROM MailActivity.dbo.MailActivities
WHERE EmailAddress = p.[EmailAddress]
AND RequestId IN
(SELECT DISTINCT(RequestId) FROM [CampaignLists]
WHERE CampaignName = @CampaignNameForDupCheck
)
)
END
アップデート:私は@CampaignNameにあるレコードを取得する必要がありとしても、重複を無視してだから私は、WHERE句に[CampaignLists] .CampaignName背中を動かし @CampaignNameForDupCheckによって最後にチェックされている別のキャンペーン/テーブルのレコード。更新されたクエリを実行すると、現在0レコードになります。
愚かな質問:「END」の後ろにセミコロンがない場合は、ここでの原因になりますか? –
ENDの後にセミコロンを付けると機能しませんでした。 – ross