Why this insert is not getting compiled :-
INSERT INTO dbo.UserGroupsToUsers
( UserID ,
LastUpdated ,
ID ,
UserGroupID
)
SELECT @MergeToUserID ,
GETDATE() ,
MAX(ID) + 1 ,
UserGroupID
FROM dbo.UserGroupsToUsers
WHERE UserID = @MergeFromUserID
Error: Column 'dbo.UserGroupsToUsers.UserGroupID' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.