程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> MSSQL >> 靜態SQL中前往數值的完成代碼

靜態SQL中前往數值的完成代碼

編輯:MSSQL

靜態SQL中前往數值的完成代碼。本站提示廣大學習愛好者:(靜態SQL中前往數值的完成代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是靜態SQL中前往數值的完成代碼正文



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
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved