I have the following stored procedure called sp_Ensure_User_Exists and I want to alter it to be smart enough to know that if there is no information for the SELECT statement - SELECT UserID FROM Users WHERE [UserID] = @sUser, to go ahead and INSERT the sUser if it doesn't exist.
Thus there will always be a record shown for the stored procedure. I do not know what SYNTAX I need to alter the stored procedure.
Thanks in advance. EE has always been good to me and this is my first time learning stored procedures!
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
-- This block of comments will not be included in
-- the definition of the procedure.
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
-- Author: Name
-- Create date:
CREATE PROCEDURE sp_Ensure_User_Exists( @sUser varchar(20) )
-- Add the parameters for the stored procedure here
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT UserID FROM Users WHERE [UserID] = @sUser