當需要呼叫外部的Stored Proceduce時,可以使用以下的範例來查詢到本身以外的資料

1.先建立一個tempTable

2.在連到Server將資料庫、帳號密碼輸入完看要執行哪個程序

3.就可以將資料暫存到tempTable裡面了

EX:

use Itemxxxxx --資料庫名稱
go
if OBJECT_ID(N'tempdb.dbo.#Lon_tempItemFiltered') is not null  --檢查有無temptable
drop table #Lon_tempItemFiltered

Select a.* into #Lon_tempItemFiltered
FROM OPENROWSET('SQLNCLI','server=stapxxx;database=Itemxxxx;Uid=sa;Pwd=xxxxx;','SET FMTONLY OFF;SET NOCOUNT ON; EXEC [Itemxxxxxxx].[dbo].[UP_xxxxxxxxxx]
@xxxx= 0,
@xxx= 10,
@xx= ''DESC'',
@xx= ''num'',
@xx= NULL,
@xx= 33,
@xx= NULL,
@xx= NULL,
@xx= 1,
@xx= 0,
@xx= NULL,
@xx= ''USA'',
@xx= NULL,
@xx = NULL,
@xx= 0') AS a;

select * from #Lon_tempItemFiltered

 

------------------------------------------------------------------------------------

--執行預存程序的字串內容

EXECUTE sp_executesql @SQLString 
EXECUTE sp_executesql N''--N是指轉uncode 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 LonChang 的頭像
    LonChang

    LonChang的部落格

    LonChang 發表在 痞客邦 留言(0) 人氣()