Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I NEED TO ORDER BY THE DATEREPORTED HERE:

SQL
SELECT        b.Client,a.Claim,CAST( a.DateReported AS dATE)AS [DATE], c.Parameter18
FROM            dbo.Claim a INNER JOIN
                         dbo.Client b ON a.Client = b.Client INNER JOIN
                         dbo.ClaimSupplement c ON a.Claim = c.Claim
						 Where Master=50
						 and a.DateReported between '3/1/16' and '6/30/16'
						 GROUP BY CAST( a.DateReported AS dATE)
						ORDER BY a.DateReported


I get the following error message:
SQL
Msg 8120, Level 16, State 1, Line 1
Column 'dbo.Client.Client' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.



how do I modify my quiery to group by datereported? Thank you

What I have tried:

SQL
SELECT        b.Client,a.Claim,CAST( a.DateReported AS dATE)AS [DATE], c.Parameter18
FROM            dbo.Claim a INNER JOIN
                         dbo.Client b ON a.Client = b.Client INNER JOIN
                         dbo.ClaimSupplement c ON a.Claim = c.Claim
						 Where Master=50
						 and a.DateReported between '3/1/16' and '6/30/16'
						 GROUP BY CAST( a.DateReported AS dATE)
						ORDER BY a.DateReported
Posted
Updated 9-Jul-16 11:02am
v3
Comments
[no name] 1-Jul-16 12:22pm    
In case of "GROUP BY" all fields other than the "GROUP FIELD" is only avaiable with an Aggregate function. You can test this by using e.g. MIN(b.Client) etc for the fields. Be Aware it's only a test and makes most probably no sense.

You Need to think about the logic.
SujayC 2-Jul-16 1:11am    
Why are you using Group by Clause in the query when there is no aggregation involved in the select statement? Use Group By clause only when you need to perform aggregation operation on columns other than the one in group by.
Try removing that group by clause in case you only need a flat list of all claims and client between the date range! or clear your requirement.
Bunty Choudhary 6-Jul-16 1:44am    
Have you tried like this :-

SELECT b.Client,a.Claim,CAST( max(a.DateReported) over (Partition By a.Client) AS DATE)AS [DATE], c.Parameter18
FROM dbo.Claim a
INNER JOIN dbo.Client b ON a.Client = b.Client
INNER JOIN dbo.ClaimSupplement c ON a.Claim = c.Claim
Where Master=50 and a.DateReported between '3/1/16' and '6/30/16'
ORDER BY a.DateReported

We can't really answer that, because we don't know what you are trying to do with your groupings.
Have a look at this: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^] - it may help you understand what the error is saying.
 
Share this answer
 
try this
SQL
SELECT        b.Client,a.Claim,CAST( a.DateReported AS dATE)AS [DATE], c.Parameter18
FROM            dbo.Claim a INNER JOIN
                         dbo.Client b ON a.Client = b.Client INNER JOIN
                         dbo.ClaimSupplement c ON a.Claim = c.Claim
						 Where Master=50
						 and a.DateReported between '3/1/16' and '6/30/16'
						 
						ORDER BY CAST( a.DateReported AS dATE)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900