我试图在 T-SQL 的 Openquery 函数中包含一个参数。我过去成功地做到了这一点,但我当前的代码不合作:
declare @bom smalldatetime
declare @eff_date smalldatetime
set @eff_date = (select min(postdate) from #temp_all)
set @bom = convert(varchar(25),dateadd(dd,-(day(@eff_date)-1),@eff_date),101)
select *
into #temp
from openquery(db,
'select l.id
,l.date
from table1 l (nolock)
inner join table2 m (nolock)
on l.id = m.id and l.date between m.start_date and m.end_date
inner join table3 d (nolock)
on l.param = d.param
where l.date = ''''' + convert(varchar(10),@bom,101) + '''''
and m.param1 = ''Y''
and m.param2 = ''N''
and param3 is null
and d.integer < 30
')
问题在于
where l.date = ''''' + convert(varchar(10),@bom,101) + '''''
线。有人可以告诉我我做错了什么吗?