I have a query here which works without the GROUP BY clause
Generally, this query is getting the user names, and specific numbers called SC which are in a part of the ALARMDETAIL. Both fields are from the query qryAlarmLog, which the result it generates with many duplicate user names and SC. I tried GROUP BY so I can get rid of the duplicated records, but it pops the following error:
I also tried using DISTINCT function but its not working, and even putting this as a subquery like this:
But this cause another error : Invalid Procedure Call
Any help would be greatly appreciate.
Code:
SELECT A.USERNAME, Mid(A.ALARMDETAILS,(InStr(1,A.ALARMDETAILS,"User",1)+4),(InStr(InStr(1,A.ALARMDETAILS,"User",1),A.ALARMDETAILS,")",1))-(InStr(1,A.ALARMDETAILS,"User",1)+4)) AS [SC] FROM qryAlarmLog AS A WHERE A.Date >= (Date()-240);
Code:
You tried to execute a query that does not include the specified expression 'Mid(A.AL.....<skipped>....)' as part of an aggregate function.
Code:
SELECT A.USERNAME, A.SC FROM (SELECT A.USERNAME, Mid(A.ALARMDETAILS,(InStr(1,A.ALARMDETAILS,"User",1)+4),(InStr(InStr(1,A.ALARMDETAILS,"User",1),A.ALARMDETAILS,")",1))-(InStr(1,A.ALARMDETAILS,"User",1)+4)) AS [SC] FROM qryAlarmLog AS A WHERE A.Date >= (Date()-240)) A GROUP BY A.USERNAME, A.SC;
Any help would be greatly appreciate.
Comment