Skip to content

Instantly share code, notes, and snippets.

@dstarh
Created September 11, 2015 15:16
Show Gist options
  • Save dstarh/787782caf0ce8a9d9f52 to your computer and use it in GitHub Desktop.
Save dstarh/787782caf0ce8a9d9f52 to your computer and use it in GitHub Desktop.
USE eshadata
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE insert_or_update_common_name
-- Add the parameters for the stored procedure here
@new_name nvarchar(1000),
@primary_key int
AS
BEGIN
SET NOCOUNT ON;
DECLARE @new_id int
insert into BaseFoodCommonName (CommonName) values (@new_name)
SET @new_id = scope_identity()
IF EXISTS (select PrimaryKey from BaseFoodCommonNameBridge where PrimaryKey = @primary_key)
BEGIN
UPDATE BaseFoodCommonNameBridge set CommonNameKey = @new_id where primaryKey = @primary_key
END
ELSE
INSERT INTO BaseFoodCommonNameBridge (PrimaryKey, CommonNameKey) values(@primary_key, @new_id)
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment