• 企业400电话
  • 网络优化推广
  • AI电话机器人
  • 呼叫中心
  • 全 部 栏 目

    网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    动态SQL中返回数值的实现代码
    POST TIME:2021-10-18 18:49
    复制代码 代码如下:

    ALTER proc [dbo].[sp_common_paypal_AddInfo]
    (
    @paypalsql varchar(max),--不包含用户表的paypalsql语句
    @paypalusersql varchar(max),--paypal用户表的sql语句
    @ebaysql varchar(max),--不包含用户表的ebaysql语句
    @ebayusersql varchar(max),--ebay的用户表sql语句
    @paypaluserwhere varchar(max),--paypal用户表查询ID语句
    @ebayuserwhere varchar(max),--ebay用户表查询ID语句
    @websql varchar(max),--web除去用户表的sql语句
    @webusersql varchar(max),--web用户表的sql语句
    @webwhere varchar(max),--web用户表where之后的sql语句
    @ebaystockflag varchar(10),--ebay订单号生成规则
    @webstockflag varchar(10)--web订单号生成规则
    )
    as
    set xact_abort on
    begin transaction mytrans
    begin try
    declare @uid int--根据语句查找用户ID
    declare @execsql varchar(max)
    declare @ebayuid int--根据语句查找用户ID
    declare @execebaysql nvarchar(max)--用sp_executesql 字段类型必须是nvarchar
    declare @sql nvarchar(max)--用sp_executesql 字段类型必须是nvarchar
    set @sql='select @a=ID from tb_TransactionCustomer where '+ convert(varchar(8000),@paypaluserwhere)
    exec sp_executesql @sql,N'@a int output',@uid output
    set @uid =ISNULL(@uid,0)--如果不这样判断 获取的值可能为null用len()获取不到长度
    --存在paypal用户id
    if(@uid>0)
    begin
    set @execsql=@paypalsql-- 存在用户信息
    set @execsql= REPLACE(@execsql,'@uid',''+convert(varchar,@uid)+'')
    end
    else
    begin
    set @execsql=@paypalusersql+@paypalsql --不存在用户信息
    end
    if(LEN(@websql)>0)--执行web语句
    begin
    exec sp_common_WebSiteorder_AddInfo @websql, @webusersql, @webwhere ,@webstockflag
    end
    if(LEN(@ebaysql)>0)--执行ebay语句
    begin
    --exec sp_common_Ebay_AddInfo @ebaysql, @ebayusersql, @ebayuserwhere ,@ebaystockflag
    SELECT * FROM tb_EbayOrder WITH (TABLOCKX)
    SELECT * FROM tb_EbayOrderList WITH (TABLOCKX)
    SELECT * FROM tb_EbayOrderUserInfo WITH (TABLOCKX)
    set @sql='select @b=ID from tb_EbayOrderUserInfo where '+ convert(varchar(8000),@ebayuserwhere)
    exec sp_executesql @sql,N'@b int output',@ebayuid output
    set @ebayuid =ISNULL(@ebayuid,0)
    if(@ebayuid>0)
    begin
    set @execebaysql=@ebaysql--存在ebayuid
    set @execebaysql= REPLACE(@execebaysql,'@ebayuid',''+convert(varchar,@ebayuid)+'')--必须替换 否则会报错误说必须声明标量变量
    end
    else
    begin
    set @execebaysql=@ebayusersql+@ebaysql --不存在ebayuid
    end
    set @execebaysql= REPLACE(@execebaysql,'@00',dbo.GetOrderNum(@ebaystockflag))--调用函数替换订单编号
    exec (@execebaysql)
    end
    exec(@execsql)
    end try
    begin catch
    if(@@TRANCOUNT>0)
    rollback transaction mytrans
    end catch
    if(@@TRANCOUNT>0)
    begin
    commit transaction mytrans
    end
    else begin
    rollback transaction mytrans
    end
    您可能感兴趣的文章:
    • MySQL 存储过程中执行动态SQL语句的方法
    • mysql存储过程 在动态SQL内获取返回值的方法详解
    • 编程经验点滴 动态SQL的拼接技巧
    • 动态SQL语句使用心得
    • 批处理 动态sql
    • MySQL存储过程的异常处理方法
    • Mysql存储过程中游标的用法实例
    • MySQL存储过程中实现执行动态SQL语句的方法
    上一篇:利用sql函数生成不重复的订单号的代码
    下一篇:sqlserver对字段的添加修改删除、以及字段的说明
  • 相关文章
  • 

    关于我们 | 付款方式 | 荣誉资质 | 业务提交 | 代理合作


    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信