DECLARE @Good INT
SELECT @Good = Good
FROM MyTable
WHERE DateDeleted IS NULL
GROUP BY ID
HAVING ID = MIN(ID)
In a stored procedure I wanna set a variable @Good. The conditions I need are that the DateDeleted
is null and the minimum ID
.
Example:
ID Good DateDeleted
-----------------------
1 5 15-12-2013
2 3 null
3 4 null
4 1 null
The result has to be 3
The error message I got is:
Msg 8120, Level 16, State 1, Line 4
Column 'MyTable.Good' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
What am I doing wrong?
Can anybody help me?
Thanks
DECLARE @Good INT
Select top 1 @Good = Good
From MyTable
Where DateDeleted is null
Order by Id
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments