我知道这不是什么大问题,但无论如何它都会让我发痒。
- 我有一个 SQL Server 2005 脚本来创建新的数据表、约束、更改一些表以添加列、更改程序以考虑表更改等。
- 一切运行良好,直到脚本遇到我的 ALTER PROCEDURE 语句。
- 错误信息如下:
“消息 156,级别 15,状态 1,过程 cpromo_Get_ConsultDetails_PromotionBan,第 59 行关键字‘PROCEDURE’附近的语法不正确。
这是我的脚本示例:
ALTER PROCEDURE [dbo].[cpromo_Get_ConsultDetails_PromotionBan]
(
@idPromoBan int,
@uid int
)
AS
begin
set nocount on;
/* 1- detail de la promo */
SELECT p.[nopromo], p.[StartDate], p.[EndDate], p.[DateText]
FROM [cpromo_PromotionBanniere] as pb
INNER JOIN [cpromo_Promotions] as p ON p.[idPromo] = pb.[idPromo]
WHERE (pb.[idPromoBan] = @idPromoBan)
/* 2 - cartes de la promo */
SELECT pis.[idCardText], ct.[nom], ct.[descr], ct.[prix], ct.[prixCoupon], ct.[qtyItem], i.[Impact]
FROM [cpromo_PromotionsItems] as pis
INNER JOIN [cpromo_Impacts] as i ON i.[idImpact] = pis.[idImpact]
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = pis.[idCardText]
WHERE (pis.[idPromoBan] = @idPromoBan)
ORDER BY i.[iorder], ct.[nom];
/* 3 - pvedettes opti */
SELECT m.[idCardText], m.[qtyCardL], m.[qtyCardM], m.[qtyCardMG], m.[qtyCardS],
ISNULL(m.[qtyCardMini], 0) as qtyCardMini,
ISNULL(m.[qtyCardMiniPTJ], 0) as qtyCardMiniPTJ
FROM [cpromo_MEMCards] as m
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = m.[idCardText]
WHERE (m.[idPromoBan] = @idPromoBan)
ORDER BY ct.[nom];
/* 4 - cart */
SELECT [idCartEl], [idCardText], [qtyL], [qtyM], [qtyMG], [qtyS],
ISNULL([qtyMini], 0) as qtyMini,
ISNULL([qtyMiniPTJ], 0) as qtyMiniPTJ
FROM [cpromo_UserCarts]
WHERE ([uid] = @uid AND [idPromoBan] = @idPromoBan);
end
ALTER PROCEDURE [dbo].[cpromo_Get_CartItems_ByPromotionBan]
(
@uid int,
@idPromoBan int
)
AS
begin
set nocount on;
SELECT ct.nom, ct.descr, p.DateText, ct.prix, ct.prixCoupon, ct.qtyItem,
uc.qtyL, uc.qtyM, uc.qtyMG, uc.qtyS,
isnull(uc.qtyMini, 0) as qtyMini,
isnull(uc.qtyMiniPTJ, 0) as qtyMiniPTJ, 3 as qteLimite
FROM cpromo_UserCarts as uc
INNER JOIN cpromo_CardText as ct ON ct.idCardText = uc.idCardText
INNER JOIN cpromo_PromotionBanniere as pb ON pb.idPromoBan = uc.idPromoBan
INNER JOIN cpromo_Promotions as p ON p.idPromo = pb.idPromo
WHERE (uc.uid = @uid) AND (uc.idPromoBan = @idPromoBan);
end
错误指向双击时遇到的第一个“end”关键字。我根本没有得到的是当一个又一个选择一个 ALTER 语句时,它运行得很好而且很流畅!当我尝试通过按 [F5] 而不进行选择来运行它们时,它给了我错误。
我试图将 ALTER 语句嵌入到另一个 BEGIN...END 中,但没有运气,它说关键字 ALTER... 附近有语法错误
编辑:可能是因为我评论了 begin 语句之后执行的修改吗?
ALTER PROCEDURE [dbo].[cpromo_Get_ConsultDetails_PromotionBan]
(
@idPromoBan int,
@uid int
)
AS
begin
------------------
-- Added column to take table changes into account blah blah blah...
------------------
set nocount on;
/* 1- detail de la promo */
SELECT p.[nopromo], p.[StartDate], p.[EndDate], p.[DateText]
FROM [cpromo_PromotionBanniere] as pb
INNER JOIN [cpromo_Promotions] as p ON p.[idPromo] = pb.[idPromo]
WHERE (pb.[idPromoBan] = @idPromoBan)
/* 2 - cartes de la promo */
SELECT pis.[idCardText], ct.[nom], ct.[descr], ct.[prix], ct.[prixCoupon], ct.[qtyItem], i.[Impact]
FROM [cpromo_PromotionsItems] as pis
INNER JOIN [cpromo_Impacts] as i ON i.[idImpact] = pis.[idImpact]
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = pis.[idCardText]
WHERE (pis.[idPromoBan] = @idPromoBan)
ORDER BY i.[iorder], ct.[nom];
/* 3 - pvedettes opti */
SELECT m.[idCardText], m.[qtyCardL], m.[qtyCardM], m.[qtyCardMG], m.[qtyCardS],
ISNULL(m.[qtyCardMini], 0) as qtyCardMini,
ISNULL(m.[qtyCardMiniPTJ], 0) as qtyCardMiniPTJ
FROM [cpromo_MEMCards] as m
INNER JOIN [cpromo_CardText] as ct ON ct.[idCardText] = m.[idCardText]
WHERE (m.[idPromoBan] = @idPromoBan)
ORDER BY ct.[nom];
/* 4 - cart */
SELECT [idCartEl], [idCardText], [qtyL], [qtyM], [qtyMG], [qtyS],
ISNULL([qtyMini], 0) as qtyMini,
ISNULL([qtyMiniPTJ], 0) as qtyMiniPTJ
FROM [cpromo_UserCarts]
WHERE ([uid] = @uid AND [idPromoBan] = @idPromoBan);
end
感谢您的任何帮助或任何提示。