OPENROWSET 与带参数的存储过程
select * from OPENROWSET( 'SQLOLEDB ', 'SERVER=SZZYCW01;uid=sa;pwd=123;Database=accountcompare ',
'SET FMTONLY OFF;SET NOCOUNT ON exec testGetDataFromSupply ' +
CONVERT(Varchar(10),@frmDatetime,20) + ', ' +
CONVERT(Varchar(10),@toDatetime,20) ') as s
其中@frmDatetime和 @toDatetime 是存储过程的两个日期参数 请高手指教!
报告提示: + 号 附近有错误
------解决方案--------------------改一下时间转换类型:
declare @frmDatetime smalldatetime,@toDatetime smalldatetime,@sql varchar(2000)
set @frmDatetime = '2007-02-03 '
set @toDatetime = '2007-06-03 '
set @sql= 'select * from
OPENROWSET( ' 'SQLOLEDB ' ', ' 'SERVER=SZZYCW01;uid=sa;pwd=123;Database=accountcompare ' ',
' 'SET FMTONLY OFF;SET NOCOUNT ON exec test ' ' ' ' '+CONVERT(varchar(10),@frmDatetime,120)+ ' ' ' ' ', ' ' ' ' '+CONVERT(varchar(10),@toDatetime,120)+ ' ' ' ' ' ' ') as a '
--print @sql
exec (@sql)