Created
September 11, 2015 15:16
-
-
Save dstarh/787782caf0ce8a9d9f52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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