Setting a variable based on a match - Then inserting into a temp table - SQL 2000

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssouhrada
    New Member
    • Jun 2008
    • 12

    Setting a variable based on a match - Then inserting into a temp table - SQL 2000

    Hello,

    I have a stored procedure that looks similar to the one below:

    Code:
    Select * from 
    table a
    inner join
    table b
    on
    a.id = b.id
    inner join
    table c
    on
    b.id = c.id
    AND
    (a.value = b.value	
    OR
    a.value = c.value
    OR
    b.value = c.value)
    How could I set a variable I declare @match, to different values based on how they were matched up in the AND(a.value = b.value OR ... etc. statement ? Also if one matched for one or more how I could I handle that case. The desired result is below:

    #temp would be a temporary table with columns id and match

    select * from #temp

    If it only matched on a
    ( (1), ("a") )
    if it matched on a and b
    ( (2), ("a,b") )
    if it matched on all three
    ( (3), ("a,b,c") )

    and so on...

    If anyone has a good example of a stored procedure with such functionality that would be very helpful.

    Thanks
Working...