I'm relatively new to sql and xml but have an application report generator that will generate the sql for queries that are very complex (to me anyway) and I try and cut and paste then to sql server. I just cant seem to get this one to work. Any help would be appreciated.
Select distinct a.IncidentID, IsNull(i.CompName,'') As 'CompanyName' , IsNull(l.UserDefined2,'') As 'SalesStageDesc' , IsNull(l.UserDefined6,'') As 'UserDefined6' , IsNull(l.UserDefined1,'') As 'SalesTypeDesc' , IsNull(g.ContactName,'') As 'User'
From tblIncident a
LEFT OUTER JOIN tblCompany i with (nolock) ON a.CompanyID = i.CompanyID
LEFT OUTER JOIN tblIncidentUtilityCross l with (nolock) ON a.IncidentID = l.IncidentIDx
LEFT OUTER JOIN (select a.ContactName, b.IncidentID from tblContact a JOIN tblIncidentContact b ON a.ContactID = b.ContactID where (b.contacttypeid = 4 or b.ContactTypeID = 3)) g ON a.IncidentID = g.IncidentID <IncidentHierarchy>
Where a.noreportdisplay !=1
if I comment out the < and keep the where clause it runs but I get the wrong answer. If someone could tell me what to do with that code it would be appreciated.