• ChrisM@Work (9/1/2015)


    yb751 (9/1/2015)


    You shouldn't have multiple CompanyID's stored this way. You'll want to normalize your data. You can't do joins that way unless the actual ID in tableB was "1,2,3,4".

    Good catch yb.

    You will need to split the string up, resolve those ID's. Use the tried and tested "House Function":

    SELECT ...

    FROM tablea a

    CROSS APPLY dbo.DelimitedSplit8k (a.CompanyID, ',') split

    INNER JOIN tableb b

    ON b.companyid = split.item

    http://www.sqlservercentral.com/articles/Tally+Table/72993/[/url]

    NP...I'm the worse for missing that kind of stuff usually. 😉

    Noticed you beat me to the Split8K sermon. LOL At least the OP should have everything he/she needs now.


    SELECT quote FROM brain WHERE original = 1
    0 rows returned