我不熟悉存储过程,我创建了一个存储过程,它从 C# 页面获取一些参数,然后将结果作为OUTPUT
参数发回。
我需要做一些计算才能得到结束日期,所以我最终使用了很多 IF 语句。但是,当我创建存储过程时,我得到了我不知道如何解决的错误,每件事似乎都是正确的!
这是存储过程代码:
CREATE PROCEDURE sp_RenewSubscription
-- Add the parameters for the stored procedure here
@Reference nvarchar(100),
@SubscribtionID nvarchar(100),
@Months int,
@Result nvarchar(200) OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @EndDate as nvarchar;
DECLARE @MonthCounts as int;
IF NOT EXISTS(SELECT [Reference] FROM [Norton].[dbo].[SubscriptionStatus] WHERE [Reference] = @Reference)
SET @Result = '0: Reference ID not found'
ELSE
IF NOT EXISTS(SELECT [Reference] FROM [Norton].[dbo].[SubscriptionStatus] WHERE [Reference] = @Reference AND [SubscribtionID] = @SubscribtionID)
SET @Result = '0: Subscribtion ID not found'
ELSE
BEGIN
SELECT TOP 1 @EndDate = [EndDate], @MonthCounts = [SubscriptionMonthCount] FROM [Norton].[dbo].[SubscriptionStatus] WHERE [Reference] = @Reference AND [SubscribtionID] = @SubscribtionID
IF @EndDate = '0'
BEGIN
UPDATE [Norton].[dbo].[SubscriptionStatus]
SET [SubscriptionMonthCount] = @Months + @MonthCounts
WHERE [Reference] = @Reference AND [SubscribtionID] = @SubscribtionID
END
ELSE
BEGIN
UPDATE [Norton].[dbo].[SubscriptionStatus]
SET [SubscriptionMonthCount] = @Months
WHERE [Reference] = @Reference AND [SubscribtionID] = @SubscribtionID
END
SET @Result = '1: Done Successfully'
END
GO
END
GO
这是我得到的错误:
消息 102,级别 15,状态 1,过程 sp_RenewSubscription,第 44 行
“END”附近的语法不正确。
消息 102,级别 15,状态 1,第 2 行
'END' 附近的语法不正确。*
谢谢,