Select * From CuDtGeneric cg left outer join CuDtattach ca on cg.icuitem=ca.xiCuItem Where (ca.nfileName=N'132312573771.doc' Or cg.ximgFile=N'132312573771.doc' Or cg.fileDownLoad=N'132312573771.doc') And fctupublic <> 'N' And ((cg.avBegin<>'' And cg.avEnd is NULL And getDate()>cg.avBegin ) Or (cg.avBegin is NULL And cg.avEnd<>'' And getDate() < cg.avEnd) Or (cg.avBegin<>'' And cg.avEnd<>'' And getDate() Between cg.avBegin And cg.avEnd) Or (cg.avBegin is NULL And cg.avEnd is NULL))