# ,优化查询语句.

www.MyException.Cn  网友分享于：2013-01-29  浏览：1次

select   gzrq   from   [@hbu1skd]

where   bh   in   (select   skdh   from   [@hbu1skmx]   where

(fybm= '续保费 'or   fybm   like   '保险费% ')and

yfybh   in   (select   bh   from   [@hbu4hkmx]

where   year(fkq)=year( ' "   +   sjfkq   +   " ')

and   month(fkq)=month( ' "   +   sjfkq   +   " ')

and   pzh= ' "   +   PZH   +   " '))

------解决方案--------------------

------解决方案--------------------

------解决方案--------------------
select gzrq from [@hbu1skd],[@hbu1skmx],[@hbu4hkmx]
where [@hbu1skd].bh = [@hbu1skmx].skdh and [@hbu1skmx].fybm= '续保费 ' and
[@hbu1skd].yfybh = [@hbu4hkmx].bh and [@hbu4hkmx].fkq= ' " + sjfkq + " ' and
[@hbu4hkmx].fkq= ' " + sjfkq + " ' and [@hbu4hkmx].pzh= ' " + PZH + " '
union
select gzrq from [@hbu1skd],[@hbu1skmx],[@hbu4hkmx]
where [@hbu1skd].bh = [@hbu1skmx].skdh and [@hbu1skmx].fybm like '保险费% ' and
[@hbu1skd].yfybh = [@hbu4hkmx].bh and [@hbu4hkmx].fkq= ' " + sjfkq + " ' and
[@hbu4hkmx].fkq= ' " + sjfkq + " ' and [@hbu4hkmx].pzh= ' " + PZH + " '
--比方说上面这个,在日期转换那,你要看看怎么样就符合了过滤条件了