DECLARE @id bigint=0,
@id int=0,
@name varchar(50) = '36',
@marks int = 'SDFGS'
@Op varchar(50) = 'UPSERT'
IF(@Op='UPSERT')
BEGIN
INSERT INTO tbl_student
(name, marks)
VALUES
(@name, @marks)
SELECT SCOPE_IDENTITY()
END
ELSE
BEGIN
UPDATE tbl_student SET
name = @name,
marks = @marks
WHERE id = @id
SELECT 'Success'
END
It throw error 'Conversion failed when converting the varchar value 'SDFGS' to data type int.'
I want to handle this error.
If error then it will be return 'Error' string.