Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007

    Unanswered: from clause issue

    I have to select one table out of two to fetch data depending on particular condition i.e. month less than current month will fetch data from table A and month equals or greater than current month will fetch data from table B

    Java Examples and Source Codes

  2. #2
    Join Date
    Nov 2004
    Provided Answers: 4
    Is this what you want?
    SELECT column1, column2
    FROM TableA
    WHERE TableA.MonthColumn < MONTH(GetDate())
    SELECT columnX, columnY
    FROM TableB
    WHERE TableB.MonthColumn >= MONTH(GetDate())
    Another possibility
    SELECT column1, 
           CASE WHEN TableA.MonthColumn < MONTH(GetDate()) 
             THEN TableA.column2 
             ELSE TableB.columnX 
    FROM TableA
       INNER JOIN TableB ON
    You do realise that you give us close to nothing to figure out what your problem is? The definition of the tables, some example data, the data of the results you are after, ... those are all things that make it possible for people, who have absolutely no idea what you are working with, to help you out.
    With kind regards . . . . . SQL Server 2000/2005/2012

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Nov 2007
    Actually i am looking for something like that

    select rows from A or B
    from switch(condition){case 1: A; case 2: B}

    assumption rows in A and B are same

Posting Permissions

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