Incorrect syntax near AS - SQL Server stored procedure [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Incorrect syntax near AS - SQL Server stored procedure [closed]



I can't create this stored procedure, the error tells me that the syntax of AS is incorrect. Please help! I have searched everywhere where my error could be or how I can redefine the stored procedure, and I have not had success.


IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[PRC_BizAgi_Obtener_Anualidad]')
AND type in (N'P'))
BEGIN
DROP PROCEDURE [dbo].[PRC_BizAgi_Obtener_Anualidad]
END

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[PRC_BizAgi_Obtener_Anualidad]
@id_NinoCentro INT
AS
DECLARE @periodo INT
SET @periodo = YEAR(GETDATE())

/*SET @id_NinoCentro = ncp.id_Nino;*/

AS <-------- INCORRECT SYNTAX
BEGIN
SET NOCOUNT ON;

SELECT
ncp.id_NinoCentro,
CAST (MAX(ncp.Ano) AS VARCHAR)+''+
CASE
WHEN MAX(ncp.Mes) > 9
THEN CAST(MAX(ncp.Mes) AS VARCHAR)
ELSE '0'+ CAST(MAX(ncp.Mes) AS VARCHAR)
END AS periodo
FROM
nino_centro_pago ncp
WHERE
periodo = @periodo
AND ncp.id_NinoCentro = @id_NinoCentro
AND ProductoFlex = '101'
AND PagaInscr = 1
GROUP BY
ncp.id_NinoCentro
HAVING
COUNT(*) >= 6
END



This question appears to be off-topic. The users who voted to close gave this specific reason:





I dont think this should be tagged as C#, it has nothing to do with C#
– maccettura
Aug 7 at 20:00





You have two AS
– Crowcoder
Aug 7 at 20:01


AS





I was about to say the same thing,I should work on my typing speed
– mahlatse
Aug 7 at 20:04




1 Answer
1



Right after the parameters, you should have AS ... BEGIN ... and that's all - right now, you have the AS twice - right after the parameters, and again after declaring and setting the @periodo variable - you should have one AS only:


AS ... BEGIN ...


AS


@periodo


AS


CREATE PROCEDURE [dbo].[PRC_BizAgi_Obtener_Anualidad]
@id_NinoCentro INT
AS
BEGIN
SET NOCOUNT ON;

DECLARE @periodo INT
SET @periodo = YEAR(GETDATE())

-- rest of your procedure here....

END

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS