Select * From CuDtGeneric cg left outer join CuDtattach ca on cg.icuitem=ca.xiCuItem Where (ca.nfileName=N'{F593D059-B5AC-4095-9E70-E61900EC4A50}.JPG' Or cg.ximgFile=N'{F593D059-B5AC-4095-9E70-E61900EC4A50}.JPG' Or cg.fileDownLoad=N'{F593D059-B5AC-4095-9E70-E61900EC4A50}.JPG') 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))