IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_new_profession_grade]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_new_profession_grade]
GO
CREATE procedure [dbo].[mps_new_profession_grade]
-- Add the parameters for the stored procedure here
@cmpid int,
@bg_grade int,
@bg_caption nvarchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

    -- Insert statements for procedure here
DECLARE @id int
SELECT TOP 1 @id=bg_id FROM mps_profession_grade WHERE @cmpid=bg_cmpid AND @bg_grade=bg_grade AND @bg_caption=bg_caption
SET @id = ISNULL(@id , 0)
IF(@id = 0)
BEGIN
INSERT INTO mps_profession_grade(bg_cmpid, bg_grade, bg_caption)
VALUES(@cmpid, @bg_grade, @bg_caption)
SELECT * from mps_profession_grade where bg_id=@@IDENTITY
END ELSE
BEGIN
SELECT 0 NONE WHERE 0=1
END
END