Sample Header Ad - 728x90

What if we do not use MAX function

0 votes
2 answers
586 views
I was supposed to use a script to get the MAX value from a table. It should have looked like this
BEGIN
DECLARE @MaxID AS INT
SELECT @MaxID = MAX([Id]) FROM dbo.suggestion
Insert into suggestion
values(@MaxID+ 1, 'value', 1);
END
Instead, due to some error, it went like this
BEGIN
DECLARE @MaxID AS INT
SELECT @MaxID = [Id] FROM dbo.suggestion
Insert into suggestion
values(@MaxID+ 1, 'value', 1);
END
It was working fine till date, due to some other issue when we started drilling down, then it came to light. I wonder how it worked till date. If somebody share their knowledge, it would be highly appreciated TIA
Asked by ispostback (223 rep)
Nov 9, 2022, 06:39 AM
Last activity: Nov 10, 2022, 12:12 PM