日期:2014-05-17  浏览次数:20464 次

头疼啊还是 关于sql server 查询行数的问题
最近 公司在改一个项目 把以前数据库是oracle的改成sql server2000
但是好多sql 语句都要改,这就遇见了令人头疼的问题
 
 sql语句为:
 select count(0) as count from (
  select distinct x.bgsxh from glaz_jymain x,glaz_jyxm j,glaz_jywt w
  where x.bgsxh=j.bgsxh and x.bgzt=4 and
  (
  x.jyry1='MXF' or x.jyry2='MXF' or x.jyry3='MXF' or x.jyry4='MXF'
  )
  and x.bgsxh=w.bgsxh and w.sh=1 and w.jyry='MXF'
  and j.jjrq>=convert(datetime,'2012-01-01',120) and j.jjrq<=convert(datetime,'2012-10-15',120)
)

用查询分析器查询总是提示:
服务器: 消息 170,级别 15,状态 1,行 9
第 9 行: ')' 附近有语法错误。



------解决方案--------------------
select count(0) as count from (
select distinct x.bgsxh from glaz_jymain x,glaz_jyxm j,glaz_jywt w
where x.bgsxh=j.bgsxh and x.bgzt=4 and
(
x.jyry1='MXF' or x.jyry2='MXF' or x.jyry3='MXF' or x.jyry4='MXF'
)
and x.bgsxh=w.bgsxh and w.sh=1 and w.jyry='MXF'
and j.jjrq>=convert(datetime,'2012-01-01',120) and j.jjrq<=convert(datetime,'2012-10-15',120)
) as t
------解决方案--------------------
select count(0) as count from (
select distinct x.bgsxh from glaz_jymain x,glaz_jyxm j,glaz_jywt w
where x.bgsxh=j.bgsxh and x.bgzt=4 and
(
x.jyry1='MXF' or x.jyry2='MXF' or x.jyry3='MXF' or x.jyry4='MXF'
)
and x.bgsxh=w.bgsxh and w.sh=1 and w.jyry='MXF'
and j.jjrq>=convert(datetime,'2012-01-01',120) and j.jjrq<=convert(datetime,'2012-10-15',120)
) K