كد دوم شما را بر طبق نام فيلدهايم بصورت زير باز نويسي كردم :
ALTER PROCEDURE [dbo].[SP_Tahlil] @date1 AS NVArchar(10) ,@date2 AS NVArchar(10),@Type as integer As
select @date1= isnull (@date1, '0000/00/00')
select @date2= isnull (@date2, '9999/99/99')
If @Type = 1
Begin
SELECT T.*
FROM View_Current T
JOIN
(
SELECT T.MachineCode
FROM View_Current t
JOIN
(
SELECT MachineCode, MAX(TestDate) AS Date
FROM View_Current
) D
on T.MachineCode = D.MachineCode
AND T.TestDate = D.Date
WHERE T.StatusID = 4
) D ON T.MachineCode = D.MachineCode
WHERE TestDate BETWEEN @date1 AND @date2;
End
GO
كه در اينصورت خطاي زير رخ داد :
Msg 8120, Level 16, State 1, Procedure SP_Tahlil, Line 17
Column 'View_Current.MachineCode' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.