我有以下代码来创建存储过程,但我似乎在这一行下面遇到了很多错误:
ON (Target.Email = Source.Email AND Target.PromoName = Source.PromoName)
此行的错误是#34;指定非布尔类型的表达式"。 我在这里做错了什么?
CREATE PROCEDURE [dbo].InsertUpdateBasicPromoEntry
@Email nvarchar(100)
,@PromoName varchar(100)
,@MaxEntries tinyint
AS
BEGIN
SET NOCOUNT ON;
MERGE [dbo].[BasicCodePromoEntries] AS Target
USING (
SELECT
@Email as Email
,@PromoName as PromoName
) AS Source
ON (Target.Email = Source.Email AND Target.PromoName = Source.PromoName)
WHEN MATCHED
THEN
BEGIN
IF Target.PeriodExpires < GETDATE()
BEGIN
UPDATE SET
Target.PeriodExpires = GETDATE()
,Target.PeriodEntries = 1
END
ELSE IF Target.PeriodExpires > GETDATE() AND Target.PeriodEntries < @MaxEntries
BEGIN
UPDATE SET
Target.PeriodEntries = Target.PeriodEntries + 1
END
ELSE
BEGIN
RETURN 1
END
RETURN 0
END
WHEN NOT MATCHED BY Target
THEN
BEGIN
INSERT INTO Target (Email, PromoName, PeriodEntries, PeriodExpires) VALUES (@Email, @PromoName, 1, DATEADD(day, 1, GETDATE()))
RETURN 0
END
END
PS:每个BEGIN和END都有下划线,说法语不正确......