Results 1 to 2 of 2

Thread: CASE help I think!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    170

    CASE help I think!!

    I need some help with this as I am not majorly SQL knowledgable and this has got me stuck at the point I do not know where to start, so hopefully someone could assist.

    I have a table called "documentsTbl" which has the following stucture and example data in it

    DocumentNo | Department1 | Department2
    -------------------------------------------------
    12345 | Accounts | Sales
    12346 | Finance | Sales
    12347 | Admin |Finance

    I then have another table called "docOwnerTbl" which has the following structure and example data in it

    Department1 | Department2 | OwningDepartment
    --------------------------------------------------------
    Accounts | Sales | Accounts
    Finance | Sales | Sales
    Admin | Finance |Admin

    Basically "documentsTbl" holds a list of documents and a department 1 and 2 column. I then have another table called "docOwnerTbl" which lists a matrix type data which I want to use to determine which department owns the document. An example of what I mean is document 12346 has department1 as Finance and department2 as Sales, if you look at the docOwnerTbl you will see that if department1 is Finance and department2 is Sales then the "OwningDepartment" is Sales.

    What I want to do is have a SELECT query that will return the "OwningDepartment" for each document in documentTbl that match the criteria in the "docOwnerTbl"

    FYI: I am doing this in MS SQL Server 2008

    I hope that makes sense?

    Thanks in advance

    Simon

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: CASE help I think!!

    I think you want a straight forward select from a join:-
    Code:
    Select DocumentNo, OwningDepartment
    From documentsTbl
    Join docOwnerTbl
      on documentsTbl.Department1 = docOwnerTbl.Department1
      and documentsTbl.Department2 = docOwnerTbl.Department2
    Does that do it for you?
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Posting Permissions

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



Click Here to Expand Forum to Full Width