SQL Server 2012 to excel

  • Hi.

    Here is an example of what I need:

    select A.name,B.address,A.case

    from A

    inner join B on A.ID = B.ID

    where case like '%AA%'

    select A.name,B.address,A.case

    from A

    inner join B on A.ID = B.ID

    where case like '%BB%'

    This will give two results as:

    Name Address Case

    A texas AA-109090

    B IL AA-109091

    Name Address Case

    A texas cc-109090

    B IL cc-109091

    I need results like:

    AACase CCCase

    AA-109090 cc-109090

    AA-109091 cc-109091

    how can I achieve the above result ?

  • How much do you know about using Integration Services?



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I tried with SSIS using two datasources and using the same excel destination

    But it resulted as

    AACase CCCase

    cc-109090

    cc-109091

    AA-109090

    AA-109091

    But I want result like this :

    AACase CCCase

    AA-109090 cc-109090

    AA-109091 cc-109091

  • First, I am assuming that you confused 'BB' and 'CC' in your sample data and query.

    It would probably be easier to use T-SQL to get your data into the required format and then use that as your source query.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • No, that is what I wanted just the casenumbers. How do I do in sql using unpivot?

  • Phil Parkin (12/11/2014)


    First, I am assuming that you confused 'BB' and 'CC' in your sample data and query.

    It would probably be easier to use T-SQL to get your data into the required format and then use that as your source query.

    I agree.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • I am able to get till this:

    AACaseCCCase

    NULL CC-109090

    NULL CC-109091

    AA-109090 NULL

    AA-109091 NULL

    Is there way I can get result in this format:

    AACaseCCCase

    AA-109090CC-109090

    AA-109091CC-109091

  • First, I am assuming that you confused 'BB' and 'CC' in your sample data and query.

    No, that is what I wanted just the casenumbers.

    Really? Your sample query includes this WHERE clause:

    where case like '%BB%'

    And yet your sample data includes this 'case':

    cc-109090

    Please explain how your WHERE clause can ever select this data.

    Moving on ...

    Try running this. Should give you an idea how to get the data you want:

    with data

    as (

    select name = 'A'

    ,cse = 'AA-109090'

    union

    select name = 'A'

    ,cse = 'CC-109090'

    )

    select AA = max(case when d.cse like 'AA%' then d.cse

    else ''

    end)

    ,CC = max(case when d.cse like 'CC%' then d.cse

    else ''

    end)

    from data d

    group by d.name

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 8 posts - 1 through 7 (of 7 total)

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