KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am looking for some advice how to optimize a couple of SQL stored procedures. With the 1st query I am doing insert, and with the 2nd one I am doing update, if the data exists. What I want to do is merge both stored procedures in one, where the query will check if the data exists than update, else insert a new row. Here is what I have at this time: update SP: ALTER PROCEDURE [dbo].[UpdateStep1](@UserId nvarchar(50), @First_Name nvarchar(50), @Last_Name nvarchar(50), @TitlePosition nvarchar(30)) AS BEGIN UPDATE Company_Information SET First_Name = @First_Name, Last_Name = @Last_Name, Title_Position=@TitlePosition, WHERE UserId = @UserId END insert SP: ALTER PROCEDURE [dbo].[InsertStep1](@UserId nvarchar(50), @First_Name nvarchar(50), @Last_Name nvarchar(50), @TitlePosition nvarchar(30)) AS BEGIN INSERT INTO Company_Information(UserId, First_Name, Last_Name, Title_Position) VALUES (@UserId, @First_Name, @Last_Name, @TitlePosition) END So, I would like to merge both SP in one, and the SP to check if there is already data for that UserId than update, else insert a new row.
Tags (comma-separated)
Save Edits
Cancel