Home Forums SQL Server 2008 SQL Server 2008 - General I need help with my query. I found part of this, but doesn't work. Please help. RE: I need help with my query. I found part of this, but doesn't work. Please help.

  • Ok, thanks. I found one of them that is making it blow up. It is that the note only has earl@dcande.com with nothing else so no space before the earl part. How do I get around this. I am using the ...

    Select s.FirstName, s.LastName, c.CustomerNo, h.OppNo, n.Note,

    SUBSTRING(SUBSTRING(n.Note,1,CHARINDEX(' ',n.Note,CHARINDEX('@', n.Note))-1),CHARINDEX('@', n.Note) - CHARINDEX(' ',REVERSE(SUBSTRING(n.Note,1,CHARINDEX('@', n.Note)-1))) + 1, 255)

    from SalesLink_SalesRep s,

    SalesLink_Prospect_SalesRepCustomerXrf c,

    Opportunity_Header h,

    Opportunity_Note n

    where c.SalesRepId = s.SalesRepId

    and c.CustomerNo = h.CustomerNo

    and h.OppNo = n.OppNo

    and s.SalesRepId in (238, 328)

    and n.Note like '%@%'

    order by CustomerNo;