Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    3

    Unanswered: CASE statement within join

    Is it possible to have a join with case statement in it?

    i.e.

    select * from a inner join b on
    case [x] then a.xid = b.xid
    case [y] then a.yid = b.yid?

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    What condition are you checking for?

    That's a pretty malformed CASE statement you've got there....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Oct 2005
    Posts
    3
    Wanted to do a join based on case statements. Instead I will just use the case statements in a function and join based on function.

    This is probably not clear, but basically to join based on case statements (i.e. join two tables based on CASE of a field) use:

    1. left outer join for each CASE, thus not using CASE in syntax, but using left outer join in place of CASE

    2. create a function that checks the field in CASE and returns value. Then join based on function i.e. dbo.wholeword(a.searchword) = b.searchword

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    BUT WHAT CONDITION DO YOU WANT TO CHECK FOR?

    Is this not a clear request?

    My best guess is that you want 2 queries and a union

    Good luck
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •