Results 1 to 3 of 3

Thread: Union Issues

  1. #1
    Join Date
    Apr 2004
    Location
    Arizona
    Posts
    75

    Answered: Union Issues

    Why does this not work?

    Select 'June 21 to Aug 1' as [Week],SUM(Time) as ReviewTime, Reviewer
    From [Plan Review Time Table]
    Where Date > '2015-07-26' and
    Date < '2015-08-1'
    Group By Reviewer
    Order By Reviewer
    Union
    Select 'Aug 8 to 15' as [Week],SUM(Time) as ReviewTime, Reviewer
    From [Plan Review Time Table]
    Where Date > '2015-08-09' and
    Date < '2015-08-15'
    Group By Reviewer
    Order By Reviewer

    I get an error that says "Incorrect syntax near the keyword 'Union' "
    Schema...
    Time = Hours reviewer put in. (Float)
    Date = The date the review was done. (Fate)
    Reviewer = Reviewer Name. (Varchar)

    The selects work on their own but not in an Union. Is this because Unions do not support aggregates? If so how should I go about this?

    Thanks

  2. Best Answer
    Posted by VLOOKUP

    "Dump the first order by.

    Select
    'June 21 to Aug 1' as [Week]
    ,SUM(Time) as ReviewTime
    , Reviewer

    From [Plan Review Time Table]
    Where Date > '2015-07-26' and
    Date < '2015-08-1'
    Group By Reviewer

    Union

    Select
    'Aug 8 to 15' as [Week]
    ,SUM(Time) as ReviewTime
    , Reviewer

    From [Plan Review Time Table]
    Where Date > '2015-08-09' and
    Date < '2015-08-15'
    Group By Reviewer
    Order By Reviewer
    "


  3. #2
    Join Date
    Oct 2014
    Posts
    268
    Provided Answers: 6
    Dump the first order by.

    Select
    'June 21 to Aug 1' as [Week]
    ,SUM(Time) as ReviewTime
    , Reviewer

    From [Plan Review Time Table]
    Where Date > '2015-07-26' and
    Date < '2015-08-1'
    Group By Reviewer

    Union

    Select
    'Aug 8 to 15' as [Week]
    ,SUM(Time) as ReviewTime
    , Reviewer

    From [Plan Review Time Table]
    Where Date > '2015-08-09' and
    Date < '2015-08-15'
    Group By Reviewer
    Order By Reviewer
    Last edited by VLOOKUP; 08-21-15 at 15:39.

  4. #3
    Join Date
    Apr 2004
    Location
    Arizona
    Posts
    75
    Thanks, that did it.

Posting Permissions

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