public DataTable GetIncidentDetails_LastNotes(string UserName, DateTime StartDate, DateTime EndDate, bool PublicOnly)
{
SqlCommand objComm = new SqlCommand();
DataAccess da = new DataAccess();
DataTable dtTempIDN = null;
try
{
objComm.CommandText = "select 'CustomerId' = i.iOwnerId, 'IncidentId' = i.iIncidentId, 'AssignedTo' = u.chUserName, 'UIDAssignedTo' = i.chAssignedTo, 'UIDInsertedBy' = i.chInsertBy, 'IssueDescription' = isnull(i.vchDesc1,'') + isnull(i.vchDesc2,''), 'Customer' = co.vchCompanyName, 'ContactId' = i.iContactid, 'CustomerContact' = cu.vchIndividualName, 'Status' = rp1.vchParameterDesc, 'Priority' = rp2.vchParameterDesc, 'NotesSeq' = iSeqNum, 'Notes1' = isnull(iwn.vchWorkNote1,''), 'Notes2' = isnull(iwn.vchWorkNote2,''), 'Notes3' = isnull(iwn.vchWorkNote3,''), 'Notes4' = isnull(iwn.vchWorkNote4,''), 'Notes5' = isnull(iwn.vchWorkNote5,''), 'InsertDate' = i.dtInsertDate, 'UpdateDate' = i.dtUpdateDate, i.iStatusId, 'PriorityId' = i.iPriorityId, 'DaysOpen' = case when i.iStatusid not in (104,101775,101776,101587) then datediff(d,i.dtInsertDate,GetDate()) else '0' end, 'DaysLastUpdated' = case when i.iStatusid not in (104,101775,101776,101587) then datediff(d,i.dtUpdateDate,GetDate()) else '0' end, 'Resolution' = isNull(res.vchUserExtension1,'') + isNull(res.vchUserExtension2,'') + isNull(res.vchUserExtension3,'') + isNull(res.vchUserExtension4,'') + isNull(res.vchUserExtension5,''), 'ProductGroup' = i.vchUser1, 'Module' = i.vchUser2 from vIncident i, vIncidentWorkNote iwn, vUsers u, vCustomer cu, vCompany co, vReferenceParameters rp1, vReferenceParameters rp2, AATZ_vCSuExtensionRecord res " +
"where (" +
"(i.dtInsertDate between @StartDate and @EndDate) " +
"or (i.dtUpdateDate between @StartDate and @EndDate and i.iStatusId in (104, 101776) " +
//This is the code that is giving me the grief. I have this sql else where in .net and it works
"and convert(char(8), convert(datetime, i.vchUser8),112) " +
"<= convert(char(8), convert(datetime, i.dtUpdateDate),112)) " +
")"+
"or (i.iStatusId not in (104,101776) and i.dtInsertDate < @StartDate) " +
") " +
"and u.chUserId = i.chAssignedTo and i.iContactId = cu.iCustomerId and i.iOwnerId = co.iCompanyId and rp1.iParameterId = i.iStatusId and rp2.iParameterId = i.iPriorityId and (i.chAssignedTo = @UserName or i.chInsertBy = @UserName ) "+
"and iWorknoteId = (select max(iWorknoteId) from vIncidentWorkNote where iIncidentId = i.iIncidentId) and ";
if (PublicOnly)
{
objComm.CommandText += " iPublishBitMask in (1,2) ";
}
else
{
objComm.CommandText += " iPublishBitMask = 0 ";
}
objComm.CommandText += "and i.iIncidentId *= res.iSystemId order by i.iIncidentId, iwn.iSeqNum";
objComm.Parameters.Add("@UserName",UserName);
objComm.Parameters.Add("@StartDate",_StartDate);
objComm.Parameters.Add("@EndDate",_EndDate);
dtTempIDN = da.GetData(objComm);
}
catch{throw;}
finally{objComm = null; da = null;}
return dtTempIDN;
}