I am converting from mysql to sql server.
While converting a select stored proc,
CREATE PROCEDURE selPropertyByAcntID
(
@in_acntID INT
)
AS
SELECT *
, SUM(CASE
WHEN u.prop_id IS NOT NULL THEN 1
ELSE 0
END) AS UnitCount
FROM
prop_details d
INNER JOIN
acnt_property a
ON
d.prop_id = a.prop_id
LEFT JOIN
unit_details u
ON
d.prop_id = u.prop_id
WHERE
a.group_id = @in_acntID
GROUP BY
d.prop_id;
It is throwing the following error:
Error: 8120 Severity 16
Column 'prop_details.prop_title' is invalid in the select list because it is not container in either an aggregate function or the GROUP BY clause.
strange -- the exact same stored proc isworking in a mysql environment.
Any help on this is much appreciated.
Copyright Notice:Content Author:「Rick」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/8431727/sql-stored-procedure-throwing-invalid-in-the-select-list-error