我正在使用SQL Server 2016
通过我的存储过程,我试图找到Recommendationsper 的数量CityID,并且遇到了语法相关的麻烦。我在底部列出了错误消息。**
DROP PROCEDURE IF EXISTS [Kittens_Dogs_AGGREGATE].[dbo].[sp_RecommendationsPerSite]
USE [Kittens_Dogs_AGGREGATE]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Tom Brady
-- Create date: 12/27/2019
-- Description: This script is to check for the amount of recommendations per site
-- =============================================
CREATE PROCEDURE [dbo].[sp_RecommendationsPerSite]
-- Add the parameters for the stored procedure here
DECLARE @CityID NVARCHAR(50),
@RunDate DATETIME = CAST(GETDATE() as date),
@DepartureTime DATETIME,
@ApplesOranges NVARCHAR(250),
@RollerCoaster NVARCHAR(50))
AS
BEGIN
SET NOCOUNT ON;
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SELECT @RApplesOranges AS ApplesOranges, Count(DISTINCT @RollerCoaster) AS RollerCoaster
FROM [Kittens_Dogs_AGGREATE].[dbo].[Recommendations] b
WHERE @CityID = 210
AND cast(@DepartureTime as date) = CAST(GETDATE() AS NVARCHAR)
AND a.ApplesOranges = b.ApplesOranges
AND cast(@DepartureTime as date) <> cast(@RunDate as date) as '2019-12-27' -- ,(select count(DISTINCT RollerCoaster)
FROM [Kittnes_Dogs_AGGREGATE].[dbo].[Recommendations] b
WHERE CityID = 210
AND cast(@DepartureDate as date) = CAST(GETDATE() AS NVARCHAR)
AND a.ApplesOranges = b.ApplesOranges
AND cast(@DepartureDate as date) <> cast(@RunDate as date)) as CAST(GETDATE() - 1 AS NVARCHAR)
FROM [Kittens_Dogs_AGGREGATE].[dbo].[Recommendations] a
WHERE CityID = 210
GROUP BY ApplesOranges
ORDER BY 1
END
GO
错误讯息
消息156,级别15,状态1,过程sp_RecommendationsPerSite,行3 [Batch Start Line 22] 关键字'DECLARE'附近的语法不正确。
消息102,级别15,状态1,过程sp_RecommendationsPerSite,行7 [Batch Start Line 22] ')'附近的语法不正确
这里发生了很多事情。
您的第二个错误是在参数定义的最后一行:@RollerCoaster NVARCHAR(50))结尾处有一个额外的')'。
接下来,您的select语句将失败,因为您有多个FROM和WHERE子句。您似乎已尝试将其注释掉,但--仅注释了一行。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。