like 里面的值是变化的要怎么写?
select b.empno,b.buildid
from
(select *
from openquery (TEST, 'select /*+ RULE */ * from db1.ta_show
where compcd=''11'' and corpcd=''C11'' and workdt like ''201301%''
') ) a,(select *
from openquery (TEST, 'select /*+ RULE */ * from db1.tb_show
where compcd=''11'' and corpcd=''C11'' and statuscd=''D''
')) b
where a.id=b.id
这样写可以查出数据,,,如果 workdt like ''201301%''
不要写死的,要是当月,
left(CONVERT(varchar(100), GETDATE(), 112),6) 能得到201301
但如果把这放进去
select b.empno,b.buildid
from
(select *
from openquery (TEST, 'select /*+ RULE */ * from db1.ta_show
where compcd=''11'' and corpcd=''C11'' and workdt like ''left(CONVERT(varchar(100), GETDATE(), 112),6)%''
') ) a,(select *
from openquery (TEST, 'select /*+ RULE */ * from db1.tb_show
where compcd=''11'' and corpcd=''C11'' and statuscd=''D''
')) b
where a.id=b.id
又不对,得怎么写好呢?
------解决方案--------------------当月的话,lz是否可以用
datediff(yy,col,getdate()) =0 and datediff(mm,col,getdate())=0
来处理?
参考
DECLARE @i DATETIME
SET @i = '2013-01-01'
SELECT CASE WHEN datediff(yy,@i,getdate()) =0 and datediff(mm,@i,getdate())=0 THEN '同月' ELSE '不同月' END
--同月
------解决方案--------------------拼接字符串然后用convert咯