2

first of all... Before someone comes here and tag it as "duplicated question" please take a better look to my question !

I have an Insert that I was using Parameters to pass the values but only one field I need to take it's value with a select, look:

INSERT INTO chamados (club, project, function, description, priority) (@club, @proj, @func, @description, @pri)";

Only the club field I need to get from a SELECT query. How Do I do that?

Obs: It's not a duplicate question. All I saw in the others threads, it was showing how to get all the values from a select, while I just need one... All the others values i'm passing by parameters/strings . . .

4
  • Do you mean that you need to perform the INSERT and then SELECT the value of the field 'club' back? Does that mean the 'club' field is AUTO_INCREMENTed or populated as a result of a table trigger? Commented Jan 21, 2013 at 16:32
  • Travis's answer solves this problem: stackoverflow.com/questions/25969/… Commented Jan 21, 2013 at 16:33
  • No, It's not @Matt. I need the select to get the value so I can perform the insert... Hope I could be clear. Thanks guys ! for answering me. Commented Jan 21, 2013 at 16:35
  • @Ghaleon ok, I think then you have your answer below. Commented Jan 21, 2013 at 16:36

1 Answer 1

3

You can mix the hard-coded variables, and the value from your table in a select statement:

INSERT INTO chamados (club, project, function, description, priority) 
SELECT club, @proj, @func, @description, @pri
FROM YourTable
Sign up to request clarification or add additional context in comments.

3 Comments

I tried... But I fail =\ INSERT INTO chamados (clube, projeto, funcionalidade, descricao, prioridade) SELECT clube FROM clubes WHERE clube = @club, @proj, @func, @descricao, @pri)"; Then I Passed all these values using parameter
@Ghaleon Move the @variables into your select clause.. they should come before your from.
Worked just perfect !! Thanks @Michael Fredrickson ! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.