×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

need a help with sub query getting group ereor, please correct

need a help with sub query getting group ereor, please correct

need a help with sub query getting group ereor, please correct

(OP)
I am using sql server report builder. I am getting group error , please help

select
opencloseid
, max(datetimestamp) as open_date
, prev_edisposition
, closed_date
from (


select
a.opencloseid,
a.datetimestamp,
a.edisposition as prev_edisposition,
min(b.datetimestamp) as closed_date

from
enrollmentshistory a
left join enrollmentshistory b
on a.opencloseid = b.opencloseid
and a.datetimestamp < b.datetimestamp
where
a.EDISPOSITION = 'Final Approval Ready'
and b.datetimestamp >=(CURRENT_TIMESTAMP-35)
group by a.opencloseid, a.datetimestamp,a.edisposition
UNION
select
a.opencloseid,
a.datetimestamp,
a.edisposition as prev_edisposition,
NULL as closed_date

from
enrollmentshistory a
left join enrollmentshistory b
on a.opencloseid = b.opencloseid
and a.datetimestamp < b.datetimestamp
where
a.EDISPOSITION = 'Final Approval Ready'
and b.datetimestamp is NULL
group by a.opencloseid, a.datetimestamp,a.edisposition


)
group by opencloseid, prev_edisposition, closed_date

RE: need a help with sub query getting group ereor, please correct

I'm thinking you may need an alias for the query within the parentheses.

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


RE: need a help with sub query getting group ereor, please correct

I don't know about SQLServer, but I have run into problems in the past when I try to do grouping on a UNION in a subquery in Oracle.
The workaround that seemed to take care of it was to add yet another layer of subquery:

CODE

select
opencloseid
, max(datetimestamp) as open_date
, prev_edisposition
, closed_date
from 
SELECT * FROM 
(
select
a.opencloseid,
a.datetimestamp,
a.edisposition as prev_edisposition,
min(b.datetimestamp) as closed_date

from
enrollmentshistory a
left join enrollmentshistory b
on a.opencloseid = b.opencloseid
and a.datetimestamp < b.datetimestamp
where
a.EDISPOSITION = 'Final Approval Ready'
and b.datetimestamp >=(CURRENT_TIMESTAMP-35)
group by a.opencloseid, a.datetimestamp,a.edisposition
UNION
select
a.opencloseid,
a.datetimestamp,
a.edisposition as prev_edisposition,
NULL as closed_date

from
enrollmentshistory a
left join enrollmentshistory b
on a.opencloseid = b.opencloseid
and a.datetimestamp < b.datetimestamp
where
a.EDISPOSITION = 'Final Approval Ready'
and b.datetimestamp is NULL
group by a.opencloseid, a.datetimestamp,a.edisposition
)
)
group by opencloseid, prev_edisposition, closed_date 
This may or may not work for you, and if it does, I'm afraid I can't tell you why - I was grasping at straws when I figured out this approach. But sometimes dumb luck is better than no luck!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close