SQL语句在VS中运行错误,在数据库中执行正确

图片说明

select (case when ub.ishandle is NUll then '未处理' when ub.ishandle='' then '未处理' else ishandle end)as 'ishandle',u.fsid,u.BuMenId,y.Chusheng,y.lunar,u.Realname,b.Name as bname from qp_hr_Yuangong y, qp_oa_Bumen b,qp_oa_username u left join qp_oa_userBirth ub on u.fsid=ub.fsid where( (y.lunar=1 and (( MONTH(y.Chusheng)=MONTH(GETDATE()) and (day(y.Chusheng) = day(dateadd(dd,3,getdate())) or day(y.Chusheng) = day(dateadd(dd,2,getdate())) or day(y.Chusheng) = day(dateadd(dd,1,getdate()))) and ((DAY(y.Chusheng)>=3))) or (MONTH(y.Chusheng)=MONTH(DATEADD(MM,1,GETDATE()) )and (day(y.Chusheng) = day(dateadd(dd,3,getdate())) or day(y.Chusheng) = day(dateadd(dd,2,getdate())) or day(y.Chusheng) = day(dateadd(dd,1,getdate())))and (DAY(y.Chusheng)<=3)))) or (( (y.lunar=1 and (( MONTH(y.Chusheng)=month((select dbo.fn_GetLunar(GETDATE()))) and (day(y.Chusheng) = day(dateadd(dd,3,(select dbo.fn_GetLunar(GETDATE())))) or day(y.Chusheng) = day(dateadd(dd,2,(select dbo.fn_GetLunar(GETDATE())))) or day(y.Chusheng) = day(dateadd(dd,1,(select dbo.fn_GetLunar(GETDATE()))))))))) ) )and u.BuMenId=b.id and u.fsid=y.fsid

SQL语句如下,选出最近三天生日的人员,包括阳历和农历。

如何单独执行查询阳历或者农历,就不会报错,于是我一开始尝试用union去连接,但是也报错了

查看全部
WLHB33
WLHB
2015/07/31 07:06
  • 数据库
  • sql
  • visual studio
  • 点赞
  • 收藏
  • 回答
    私信

2个回复