code_junkie

Problem with SELECT INTO using local variables

Nov 13th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. SELECT id INTO var_name FROM table1 WHERE some_column='something' LIMIT 1;
  2. INSERT INTO table2 (`number`) VALUES (@var_name);
  3.  
  4. INSERT INTO table2 (`number`)
  5. SELECT id FROM table1 WHERE some_column='something' LIMIT 1
  6.  
  7. declare @var_name varchar(100);
  8. SELECT id INTO @var_name FROM table1 WHERE some_column='something' LIMIT 1;
  9. INSERT INTO table2 (`number`) VALUES (@var_name);
  10.  
  11. insert into table2 ('number')
  12. select id
  13. from table1
  14. where some_column = 'something' LIMIT 1;
Add Comment
Please, Sign In to add comment