解決sql server中批處理過程中“'CREATE/ALTER PROCEDURE 必須是查詢批次中的第一個語句”


在批處理中加字段或表或視圖或存儲過程是否存在的判斷

-----------------------------------------line-------------------------------------------------
USE [p20-cy-2966];
/*
   V1.0.2版本SQL批處理
*/

--判斷某表的某字段是否存在
if (not exists(select * from syscolumns where id=object_id('BlanceManageO2O') and name='OrderInfoNum'))
ALTER TABLE BlanceManageO2O ADD OrderInfoNum INT DEFAULT 0;

GO

--判斷某存儲過程是否存在
if (exists (select * from sys.objects where name = 'sp_BlanceOrderInsertCatering'))
    drop proc sp_BlanceOrderInsertCatering
GO
CREATE PROCEDURE [dbo].[sp_BlanceOrderInsertCatering] 
    -- 由存儲過程SettlementManageO2O 中傳入值
    @ShopId int,
    @AgentId int,
    @BlanceId int,
    @IndustryId int,  --行業類型 行業Id 1-零售 2-餐飲 3-酒店 4-娛樂 5-家政 6-旅游 7-二手
    @Year    int,                                        --
    @Month  int,                                        --
    @Day    int    ,                                       --
    @O2OShopPercent decimal(18,2),                      --020提成百分比
    @WeixinPoundaga decimal(18,2),                      -- 獲取系統設置PlatBaseSet表中的微信支付手續費百分比  
    @TransferPriceSum     decimal(18,2) output   
AS    
BEGIN
    --處理程序
END

GO

--判斷某存儲過程是否存在
if (exists (select * from sys.objects where name = 'SettlementManageCatering'))
    drop proc SettlementManageCatering
GO
CREATE PROCEDURE [dbo].[SettlementManageCatering]
AS
BEGIN
   --處理程序
END

GO

-----------------------------------------line-------------------------------------------------

USE [p20-cy-2967];
/*
   V1.0.2版本SQL批處理
*/

--判斷某表的某字段是否存在
if (not exists(select * from syscolumns where id=object_id('BlanceManageO2O') and name='OrderInfoNum'))
ALTER TABLE BlanceManageO2O ADD OrderInfoNum INT DEFAULT 0;

GO

--判斷某存儲過程是否存在
if (exists (select * from sys.objects where name = 'sp_BlanceOrderInsertCatering'))
    drop proc sp_BlanceOrderInsertCatering
GO
CREATE PROCEDURE [dbo].[sp_BlanceOrderInsertCatering] 
    -- 由存儲過程SettlementManageO2O 中傳入值
    @ShopId int,
    @AgentId int,
    @BlanceId int,
    @IndustryId int,  --行業類型 行業Id 1-零售 2-餐飲 3-酒店 4-娛樂 5-家政 6-旅游 7-二手
    @Year    int,                                        --
    @Month  int,                                        --
    @Day    int    ,                                       --
    @O2OShopPercent decimal(18,2),                      --020提成百分比
    @WeixinPoundaga decimal(18,2),                      -- 獲取系統設置PlatBaseSet表中的微信支付手續費百分比  
    @TransferPriceSum     decimal(18,2) output   
AS    
BEGIN
    --處理程序
END


GO

if (exists (select * from sys.objects where name = 'SettlementManageCatering'))
    drop proc SettlementManageCatering
GO
CREATE PROCEDURE [dbo].[SettlementManageCatering]
AS
BEGIN
   --處理程序
END

GO

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM