Need help in following query

  • Hi,

    i have two table like below.

    Table1

    Id Name

    1 a,b,c

    2 b,c

    3 c,d

    4 a,b,c,d

    Table2

    Id Name

    a aaa

    b bbb

    c ccc

    d ddd

    the output should be the following..

    Output:

    id name

    1 aaa,bbb,ccc

    2 bbb,ccc

    3 ccc,ddd

    4 aaa,bbb,ccc,ddd

    Please let me know if any body knows..

  • Honestly, you should first be looking at normalising the table design. The first is not normalised and hence you have these kinds of problems.

    To solve it in the mean time, get the function DelimitedSplit8k (it's from an article on this site, google will find it) and use that to split the comma-delimited list up. You can then join with a LIKE predicate.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

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