动态SQL中返回数值的实现代码

来源:asp之家 时间:2012-01-05 18:53:54 

 代码如下:


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

标签:动态SQL,返回数值
0
投稿

猜你喜欢

  • SQL Server中两种修改对象所有者的方法

    2009-01-15 13:10:00
  • Linux安装卸载Mysql数据库

    2011-01-29 16:45:00
  • Ajax缓存解决办法

    2008-10-22 13:42:00
  • 用ASP显示ACCESS数据库的GIF图象

    2008-11-16 18:09:00
  • Microsoft JET Database Engine 错误 '80040e21' 所有记录中均未找到搜索关键字

    2009-08-30 13:07:00
  • 像聪明女孩穿衣服那样设计网页文字

    2007-11-06 16:45:00
  • 网站导航设计模式指南

    2011-03-04 16:12:00
  • 导航设计与信息架构

    2008-01-13 22:08:00
  • HTML 5新增的元素

    2007-10-29 12:39:00
  • 在Asp程序中取得表单所有内容的方法

    2010-04-24 16:07:00
  • asp 性能测试报告 学习asp朋友需要了解的东西

    2011-03-09 10:57:00
  • ASP 调用带参数输出的COM接口

    2011-03-17 10:59:00
  • asp如何制作一个安全的页面?

    2010-06-29 21:22:00
  • 使用带批注的 XDR 架构创建 XML 视图

    2008-09-04 14:24:00
  • document.createElement()用法及注意事项

    2008-04-21 15:16:00
  • 商业价值与用户价值的平衡

    2008-12-10 18:42:00
  • ubuntu下简单配置mysql数据库

    2009-07-31 09:17:00
  • 妙用dw图层与表格进行网页布局

    2009-07-14 21:57:00
  • 如何用SA-FileUp上传一个单纯的HTML文件?

    2010-05-18 18:29:00
  • 全面了解CSS内置颜色(color)值

    2008-11-19 12:26:00
  • asp之家 网络编程 m.aspxhome.com