sqlhelper10
sqlhelper10

Reputation: 1

Insert statement in procedure with parameters

Well I have this Procedure with this insert statement:

CREATE PROCEDURE add_job
AS
INSERT INTO jobs(job_id, job_title) VALUES('IT_DBA', 'Database Administrator');
GO;

Instead of hardcoding the values I'd like to use parameters so every time I call this procedure I should be able to insert new values.

Upvotes: 0

Views: 148

Answers (3)

R. Moshiur
R. Moshiur

Reputation: 39

CREATE PROCEDURE insert_statement(parameter_name VARCHAR(100))
BEGIN
    INSERT INTO db_table VALUES (default, parameter_name);
END;

Upvotes: 1

sinfella
sinfella

Reputation: 286

CREATE PROCEDURE [dbo].[add_job]

@job_id VarChar (50),
@job_Title VarChar (50)
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO [dbo].[jobs]
  ([job_id] 
 , job_title)
 VALUES
(@job_id, @job_title)
END;

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269803

Parameters would look like:

CREATE PROCEDURE add_job (
    @job_id varchar(255),
    @job_title varchar(255)
) AS
BEGIN
    INSERT INTO jobs(job_id, job_title)
        VALUES(@job_id, @job_title);
END;

Of course, you haven't specified the types of the columns, so I just made up the varchar(255) as a reasonable type.

Upvotes: 1

Related Questions