解决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

 

转载于:https://www.cnblogs.com/smartsmile/p/7666019.html

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值