Incorrect syntax near the keyword 'AS' in procedure
Why does 开发者_如何学Gomy procedure give me:
Msg 156, Level 15, State 1, Procedure CountAantalModules, Line 10
Incorrect syntax near the keyword 'AS'.
when I try to alter it?
USE [SomaData]
GO
/****** Object: StoredProcedure [dbo].[CountAantalModules] Script Date: 08/04/2011 15:09:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CountAantalModules]
(
@prodorder as int,
@result int output
)
AS
SET NOCOUNT ON;
SELECT @result = COUNT(ORD.ORDERNUMMER) AS AantalModuleOrders
FROM Kostenposten AS KP
INNER JOIN Orders AS ORD ON ORD.Ordernummer = KP.Ordernummer
WHERE ((KP.KPNR = '170' AND KP.SOORT='LadeFront' OR KP.SOORT='GlasLadeFront') OR
(KP.KPNR = '250' AND KP.SOORT='LadeFront')) AND ORD.PRODUCTIEORDER = (@prodorder)
You are setting a variable and trying to select it at the same time.
I think instead of:
SELECT @result = COUNT(ORD.ORDERNUMMER) AS AantalModuleOrders
You might have just meant:
SELECT COUNT(ORD.ORDERNUMMER) AS AantalModuleOrders
Or possibly:
SELECT @result = COUNT(ORD.ORDERNUMMER)
Its an assignment to an (output) variable so cannot be aliased as its not a column in a result set.
Perhaps you'll need quotes around the AantalModuleOrders, Since it is a string (want to name the column that way):
SELECT COUNT(ORD.ORDERNUMMER) AS 'AantalModuleOrders'
Get rid of AS AantalModuleOrders
. You want the value of the count(*)
in @result
, so you don't need to give the column an alias name, as there is technically no column
I don't know whether the alias AantalModuleOrders is necessary, I would suggest removing the alias and using following statement:
SELECT @result = COUNT(ORD.ORDERNUMMER)
精彩评论