Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HEllo Team,

I am getting the Error As follows in SQL.

Msg 8127, Level 16, State 1, Line 1
Column "CustomerloanOCR.FILELOGID" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.

I have the Query as Follows:
SQL
select count(ID) as Count from CustomerloanOCR with (nolock) where  filelogid  =
(select top (1) filelogid from customerloanocr with (nolock) where assignedto = 1
AND createdon >='2014-01-01 00:00:00'  and createdon<='2014-04-04 00:00:00' and processed = 0 and isnull(deleted,0) = 0 order by id asc )
 and processed = 0 and assignedto = 1  AND isnull(DELETED,0) = 0  Order by FILELOGID, RECORDNO


Kindly guide me ,where I am Getting Wrong.

Thanks
Harshal Raut.
Posted
Comments
Daniele Rota Nodari 15-Apr-14 4:32am    
Hi.
If you want Count(ID) value for each combination of FILELOGID and RECORDNO then you have to add a GROUP BY clause similar to the last ORDER BY (insert "GROUP BY FILELOGID, RECORDNO" before "Order by FILELOGID, RECORDNO"); otherwise (if you want Count(ID) for any FILELOGID and RECORDNO) remove the last ORDER BY clause at all.
Regards,
Daniele.
R Harshal 15-Apr-14 7:20am    
Thank You So Much Daniele Rota Nodari .
Thanks A Lot.Its Working.
R Harshal 15-Apr-14 7:20am    
Thank You So Much Daniele Rota Nodari .
Thanks A Lot.

1 solution

Try this:
SQL
select count(ID) as Count from
    (
        select top (1) filelogid as ID
        from customerloanocr
        with (nolock)
        where assignedto = 1
        AND createdon between '2014-01-01 00:00:00'  and '2014-04-04 00:00:00'
        and processed = 0 and isnull(deleted,0) = 0
        AND isnull(DELETED,0) = 0
        order by id asc
    ) as subTable
 
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