Ok So I have been playing with stored procedures for a couple weeks. I have had great success with these. Until today. I created a stored procedure with SSMS 2016 using this code.
IF ( OBJECT_ID('dbo.sp_frmCPS_GetCurECOStatus') IS NOT NULL )
DROP PROCEDURE dbo.sp_frmCPS_GetCurECOStatus
CREATE PROCEDURE dbo.sp_frmCPS_GetCurECOStatus
@Partnum VARCHAR(MAX) =NULL
SET NOCOUNT ON
SELECT MAX ([ECOno]), [Status]
WHERE [PartNo]= @Partnum
GROUP BY [ECOno]
ORDER BY [ECOno] DESC
When I run it i get this error:
Msg 8120, Level 16, State 1, Procedure sp_frmCPS_GetCurECOStatus, Line 6 [Batch Start Line 8]
Column 'dbo.tblSqlECO.Status' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
What I'm trying to achieve is the get the last ECO Number from the table and be able to return the "Status" column Value of that row for some Visual Basic.Net code I'm working on.