如何在openquery语句中传递date参数

时间:2014-05-31 10:46:11

标签: oracle sql-server-2005 openquery

我有一个程序

Create procedure [dbo].[daily_stats]
@date datetime, @grouping varchar(150)
as

select callid,campaignid,dnis,anidigits,callstarttime,totalcalltime,agenttalktime,agentid,abandon,queuewaittime,calltype,call_acw,datestamp,bill_flag,
queueid,queuename,calldelayed, callholdtime, shortcall,ctr_name,role_name,team_name,callhold_times,agent_fullname,xferto,timeafterxfer,
obcallids,obcalls,obtime,orgname, getdate() as ImportedDate

into #tempid7

from openquery(orapr2, 'select * from sp_calldetail
where trunc(callstarttime) >= trunc(sysdate-1) and abandon in (0,1) and (upper(campaignid) in (''SYNAPSE'', ''SYNAPSECALLBACK'') or campaignid like ''ME%'')')

我想在@date传递trunc(sysdate-1)值。我该怎么做?

2 个答案:

答案 0 :(得分:0)

  

如何在openquery语句中传递date参数

您可以尝试此解决方案

,而不是使用openquery功能
EXEC LINKEDSVR_BUH_03.TestUPSERT.dbo.Customer_Select @pCustomerID = 2
EXEC LINKEDSVR_BUH_03..dbo.Customer_Select @pCustomerID = 2 -- It uses default database (see Catalog property for linked server)

或者

EXEC (N'TestUPSERT.dbo.Customer_Select ?', 2) AT LINKEDSVR_BUH_03
EXEC (N'dbo.Customer_Select ?', 2) AT LINKEDSVR_BUH_03 -- It uses default database (see Catalog property for linked server)
                            ^----- parameter placeholder
                                ^----- parameter value

答案 1 :(得分:0)

我发现必须将日期时间转换为Oracle格式-例如:

TO_DATE(''''' + CONVERT(varchar(10), @From, 120) + ''''',''''YYYY-MM-DD'''')

否则它将返回错误-无效月份