I'm working on a project with C# and a SQL Server database. Right now I have to write a stored procedure, which needs to get a MAX value from 3 different columns.
My code looks like this:
CREATE PROCEDURE [dbo].[sp_GetClass]
@surname nvarchar(50),
@maxClass int OUT
AS
SELECT @maxClass = MAX
FROM (VALUES (Programming), (Mathematics), (Physics))
FROM MissLess
WHERE Surname LIKE '%' + @surname + '%'
GO
I get an error for the second FROM and I'm not sure how to fix it.
The idea is to make it get the max value from those columns, when a surname is input. When no input is made(press enter) it just shows the max value from those 3 columns across all surnames.
Excuse me, if the formatting or the questions is not asked right, it's my first post here.
EDIT: made an error in @name, it's supposed to be @surname; and Name is supposed to be Surname. EDIT FINAL: Thanks for the awesome help. I'm an ultra newbie in all of this, but it all seems like great fun. Was so close to just giving up, but decided to give this a shot. Thanks for all the answers!!!