IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_new_manage_grade]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_new_manage_grade]
GO


CREATE procedure [dbo].[mps_new_manage_grade]
-- Add the parameters for the stored procedure here
@cmpid int,
@mg_grade int,
@mg_caption nvarchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- Insert statements for procedure here
DECLARE @id int
SELECT TOP 1 @id=mg_id FROM mps_manage_grade WHERE @cmpid=mg_cmpid AND @mg_grade=mg_grade AND @mg_caption=mg_caption
SET @id = ISNULL(@id , 0)
IF(@id = 0)
BEGIN
INSERT INTO mps_manage_grade(mg_cmpid, mg_grade, mg_caption)
VALUES(@cmpid, @mg_grade, @mg_caption)
SELECT * from mps_manage_grade where mg_id=@@IDENTITY
END ELSE
BEGIN
SELECT 0 NONE WHERE 0=1
END
END