Hi all,
My table has fields:
account,agentID, date, conclusion_code
with duplicate account exist now I need to create another table with distinct account and choose other values based on the latest date
This is what I tried
CREATE TABLE #UniqueAccount2 (
Account VARCHAR(50),
Agent int,
Conclusion_cd Varchar(2),
)
INSERT INTO #UniqueAccount2
SELECT DISTINCT Account, agent, conclusion_cd
FROM dbo.tbl_mainTable
group by Account
where date = max(date)
it doesnt work.
error msg: agent is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
Please help me to fix it. Thanks in advance
My table has fields:
account,agentID, date, conclusion_code
with duplicate account exist now I need to create another table with distinct account and choose other values based on the latest date
This is what I tried
CREATE TABLE #UniqueAccount2 (
Account VARCHAR(50),
Agent int,
Conclusion_cd Varchar(2),
)
INSERT INTO #UniqueAccount2
SELECT DISTINCT Account, agent, conclusion_cd
FROM dbo.tbl_mainTable
group by Account
where date = max(date)
it doesnt work.
error msg: agent is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
Please help me to fix it. Thanks in advance