gpt4 book ai didi

sql-server-2005 - SQL Server 脚本 : ALTER PROCEDURE - Executing multiple ALTER PROCEDURE into one script without having to select each of the ALTER one after another

转载 作者:行者123 更新时间:2023-12-02 05:27:43 26 4
gpt4 key购买 nike

我知道这不是什么大问题,但还是让我觉得很痒。

  1. 我有一个 SQL Server 2005 脚本来创建新的数据表、约束、更改一些表以添加列、更改过程以将表更改考虑在内等。
  2. 一切正常,直到脚本遇到我的 ALTER PROCEDURE 语句。
  3. 错误信息如下:

"Msg 156, Level 15, State 1, Procedure cpromo_Get_ConsultDetails_PromotionBan, Line 59 Incorrect syntax near the keyword '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... 附近存在语法错误

EDIT: Can it be because I comment the modifications performed after the begin statement?

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

感谢任何帮助或提示。

最佳答案

这个答案不是我的,因为它是我得到的所有答案的结果。每个答案都有解决方案的一部分,所以我想把解决方案的所有要点都放在一个答案上。

  1. 在每个 ALTER PROCEDURE 语句之间插入一个“GO”语句(每个回答的人)
  2. 确保空白区域(Arvo)中没有不可见字符
  3. BEGIN...END 语句被证明是不必要的 (Mayo)
  4. 按照过程核心在 AS...GO 中删除分号似乎也造成了一些麻烦 (Mayo)
  5. 我的问题编辑中描述的程序核心内的注释无关紧要,一旦检查了上述几点,它就不会导致任何错误(我自己)

希望有一天这会对某人有所帮助。

感谢大家,功劳归于你们!

关于sql-server-2005 - SQL Server 脚本 : ALTER PROCEDURE - Executing multiple ALTER PROCEDURE into one script without having to select each of the ALTER one after another,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1432757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com