jp2msft
2008-11-11 17:23:01 UTC
I've got this simple query:
SELECT EmpName, EmpBadge
FROM Employees
WHERE EmpName=@EmpName1
Occasionally, there are duplicates (an employee is terminated, then hired
again at a later date). Because of this, we have added an ID field that is
automatically incremented whenever a new employee is added.
To prevent duplicates, I need to modify the query above to something like
this code below that does NOT work as it is written:
SELECT EmpName, EmpBadge
FROM Employees
WHERE (EmpName=@EmpName1) AND (Max(ID))
Obviously, the Max(ID) parameter is causing the failure.
I do not want the ID returned as part of the query, or I will need to write
another query to filter the ID out of the results.
So, how exactly should this query be written?
SELECT EmpName, EmpBadge
FROM Employees
WHERE EmpName=@EmpName1
Occasionally, there are duplicates (an employee is terminated, then hired
again at a later date). Because of this, we have added an ID field that is
automatically incremented whenever a new employee is added.
To prevent duplicates, I need to modify the query above to something like
this code below that does NOT work as it is written:
SELECT EmpName, EmpBadge
FROM Employees
WHERE (EmpName=@EmpName1) AND (Max(ID))
Obviously, the Max(ID) parameter is causing the failure.
I do not want the ID returned as part of the query, or I will need to write
another query to filter the ID out of the results.
So, how exactly should this query be written?