By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,678 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,678 IT Pros & Developers. It's quick & easy.

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

P: 12

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

Expand|Select|Wrap|Line Numbers
  2. Select * from 
  3. table a
  4. inner join
  5. table b
  6. on
  7. =
  8. inner join
  9. table c
  10. on
  11. =
  12. AND
  13. (a.value = b.value    
  14. OR
  15. a.value = c.value
  16. OR
  17. 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.

Nov 21 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.