Aa Aaa
Aa Aaa

Reputation: 53

Insert into table (select from another table) and some parameters

I want to insert into one table selecting values from another table and some with paramters.

CREATE  PROCEDURE `insertuser`(
    IN `param1` VARCHAR(50)

)
BEGIN

insert into users(firstname,lastname,email) 
select name,nickname,@param1 from members
where id=3;
END

I fill param1 but the query insert null to email what I need to do?

Upvotes: 2

Views: 98

Answers (1)

Madhur Bhaiya
Madhur Bhaiya

Reputation: 28854

@ symbol is used to define Session variables (accessible to the Session everywhere). You don't need to use @ here, as you are using the input parameter value from the Stored procedure.

Try the following instead:

DELIMITER $$
CREATE  PROCEDURE `insertuser`(IN `param1` VARCHAR(50))
  BEGIN

    INSERT INTO users(firstname,lastname,email) 
    SELECT name,nickname,param1 -- remove @ from @param1 here
    FROM members
    WHERE id=3;
END$$
DELIMITER ;

Upvotes: 1

Related Questions