Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Posts
    13

    Exclamation Unanswered: Query Problem... please help

    I have a table named "tblDate" :

    s_month | s_year | c_month | c_year
    Jan | 2002 | Jan | 2002
    Feb | 2002 | May | 2003
    May | 2004 | Jun | 2004
    Aug | 2004 | Nov | 2005

    I need a query to display the record like this :

    s_month | Year | c_month
    Jan | 2002 | Jan
    Feb | 2002 | ""
    "" | 2003 | May
    May | 2004 | Jun
    Aug | 2004 | ""
    "" | 2005 | Nov

    Any idea ?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select s_month
         , s_year as [Year]
         , c_month
      from tblDate
     where s_month = c_month  
       and s_year  = c_year  
    union all
    select s_month
         , s_year 
         , null
      from tblDate
     where s_month <> c_month  
        or s_year  <> c_year  
    union all
    select null
         , c_year 
         , c_month
      from tblDate
     where s_month <> c_month  
        or s_year  <> c_year
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2004
    Posts
    13
    Thanks, but i am getting this output :

    s_month | Year | c_month
    Jan | 2002 | Jan
    Feb | 2002 | ""
    "" | 2003 | May
    May | 2004 | ""
    "" | 2004 | Jun
    Aug | 2004 | ""
    "" | 2005 | Nov

    the record "May | 2004 | Jun" had separate to two different rows.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by zilvito
    the record "May | 2004 | Jun" had separate to two different rows.
    what's so special about that combo?

    why wouldn't you want it split like the others?

    what are the rules for deciding when not to split?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jun 2004
    Posts
    13

    Query Problem... please help (Resolved)

    Alright, thanks. You save my life.

Posting Permissions

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