seperate data in 1 row

  • Thank you,it is working

     also trying to this select statement to email add this code:

    WHEN a. [Person Email]  is NULL
      THEN (SELECT Email FROM [dbo].[PersonEmail] INNER JOIN dbo.vw_Person ON [dbo].[PersonEmail].[name]= dbo.vwPerson.[Person Name] WHERE vw_Person_.[Person Email] IS null )

     get errorI
    Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.

  • It's just saying that the PersonEmail column has a different collation from the Person Name column.  Use a COLLATE clause on one of them to match it to the collation of the other, or use a COLLATE DATABASE DEFAULT clause on both of them.

    John

  • Thank you,it works only if I run it outside of my statement,but if I run the full code 
    Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

  • When you ran it outside your statement you should have seen what the problem is.  The subquery returns more than one value of Email.  Which of those values do you want it to use?  Try using a TOP 1 clause to restrict the subquery result to a single value.

    John

  • if do select top 1, I get 1st email for person correct and the rest get email of that person, I need people have their emails mapped correctly.

  • Krasavita - Thursday, November 1, 2018 9:18 AM

    if do select top 1, I get 1st email for person correct and the rest get email of that person, I need people have their emails mapped correctly.

    Post your code, nicely formatted, using the if code blocks to keep the code formatted.

  • WHEN a.[Person Email] IS NULL AND a.[person name] IS NOT null THEN
                      (   SELECT     TOP 1 Email COLLATE DATABASE_DEFAULT
                            FROM      [dbo].[vw_PersonEmail]
                          INNER JOIN dbo.R1_Person
                             ON [dbo].[vw_PersonEmail].[name] COLLATE DATABASE_DEFAULT = dbo.R1_Person.[Person Name]
                           WHERE      R1_Person_10032018.[Person Email] IS NULL)
  • Krasavita - Thursday, November 1, 2018 9:36 AM

    WHEN a.[Person Email] IS NULL AND a.[person name] IS NOT null THEN
                      (   SELECT     TOP 1 Email COLLATE DATABASE_DEFAULT
                            FROM      [dbo].[vw_PersonEmail]
                          INNER JOIN dbo.R1_Person
                             ON [dbo].[vw_PersonEmail].[name] COLLATE DATABASE_DEFAULT = dbo.R1_Person.[Person Name]
                           WHERE      R1_Person_10032018.[Person Email] IS NULL)

    All the code. Also, format it and use the IF CODE blocks to keep the code formatted.

  • You don't even have consistent table names in there.  Sometimes you have 10032018 in the table name and sometimes you don't.  If you don't care about your code, nobody else is going to.  Never mind - try this.  The correlated subquery probably isn't the best from a performance point of view, but it may just get you over the line.  I recommend you get someone in to look at this, since you seem to be struggling, and the database design appears to be far from optimal.

    WHEN a.[Person Email] IS NULL AND a.[person name] IS NOT NULL THEN (
        SELECT TOP 1 Email COLLATE DATABASE_DEFAULT
        FROM dbo.vw_PersonEmail v
        WHERE a.[Person Name] = v.name COLLATE DATABASE_DEFAULT
        )

    John

    Edit: if there's a one-to-one mapping between "a" and vw_PersonEmail, then you don't need the TOP 1.  If you do need to keep it, however, you need an ORDER BY clause in your subquery so that you know what you're sorting on when you choose your top value.

  • Thank you for your help

  • Hello
     need to fix data for Persan name can you please help

    DSPNRegionCountryPersonNamePerson Email_oldCountry Program
    Bad Data
    67946740127CAROjapanandgela Toluhi karagiandgela.toluhi@jus.org karagi.akinmade@jus.orgjapan
    good data
    67946740127CAROjapanandgela Toluhi andgela.toluhi@jus.org japan
    67946740127CAROjapankaragikaragi.akinmade@jus.orgjapan
    Bad Data
    67506740142LACROHaitiandgela Toluhi Olufunbi Olaogunandgela.toluhi@jus.org olufunbi.olaogun@jus.orgjapan
    Good data
    67506740142LACROHaitiandgela Toluhi andgela.toluhi@jus.org japan
    67506740142LACROHaitiOlufunbi Olaogunolufunbi.olaogun@jus.orgjapan
    Bad data
    15506740131CAROjapanandgela Toluhi Sasha Usman Adia, Oro-yevge andgela.toluhi@jus.org Sasha.usman@jus.org oro-yevge.adia@jus.orgjapan
    Good data
    85036740131CAROjapanandgela Toluhi andgela.toluhi@jus.org sjapan
    85036740131CAROjapanSasha Usman Adia  Sasha.usman@jus.org japan
    85036740131LACROHaiti Oro-yevge  oro-yevge.adia@jus.orgjapan
  • Krasavita - Friday, November 9, 2018 11:30 AM

    Hello
     need to fix data for Persan name can you please help

    DSPNRegionCountryPersonNamePerson Email_oldCountry Program
    Bad Data
    67946740127CAROjapanandgela Toluhi karagiandgela.toluhi@jus.org karagi.akinmade@jus.orgjapan
    good data
    67946740127CAROjapanandgela Toluhi andgela.toluhi@jus.org japan
    67946740127CAROjapankaragikaragi.akinmade@jus.orgjapan
    Bad Data
    67506740142LACROHaitiandgela Toluhi Olufunbi Olaogunandgela.toluhi@jus.org olufunbi.olaogun@jus.orgjapan
    Good data
    67506740142LACROHaitiandgela Toluhi andgela.toluhi@jus.org japan
    67506740142LACROHaitiOlufunbi Olaogunolufunbi.olaogun@jus.orgjapan
    Bad data
    15506740131CAROjapanandgela Toluhi Sasha Usman Adia, Oro-yevge andgela.toluhi@jus.org Sasha.usman@jus.org oro-yevge.adia@jus.orgjapan
    Good data
    85036740131CAROjapanandgela Toluhi andgela.toluhi@jus.org sjapan
    85036740131CAROjapanSasha Usman Adia  Sasha.usman@jus.org japan
    85036740131LACROHaiti Oro-yevge  oro-yevge.adia@jus.orgjapan

    First you only wanted the first email address, now you want to match email addresses to names?  I give up.  You don't even seem able to follow simple guidelines for post questions even when you are pointed directly to an article that would help you do so.  You don't give the complete picture of what you are trying to accomplish, just little pieces so it is like pulling hens teeth to figure out what it is you are you trying to accomplish.

  • You haven't given enough information for anyone to come up with a reasonable solution.  In fact, it looks like your "Good data" isn't so good. Based on the emails, I suspect that "Sasha Usman Adia" should, in fact, just be "Sasha Usman" and that Oro-yevge should be Oro-yevge Adia.  Also, there is no way that anybody can get LACRO HAITI from your bad data for oro-yevge.adia@jus.org.

    PS: I suspect that there isn't going to be any way to automate this cleanup.  You may just have to do it manually unless you can find it in a better form somewhere upstream of this data.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 13 posts - 31 through 42 (of 42 total)

You must be logged in to reply to this topic. Login to reply