0

Environment Details. Windows 10 - Python3.5 - Flask - SQL SERVER - PyOdbc.

cur.execute("insert into T1 (ID_CUSTOMER, ID_ENVIRONMENT) values (?, ?)",
                    select id from CUSTOMER where name = form['customerId'],
                    select id from ENVIRONMENT where name = form['environmentId'],
                    )

1 Answer 1

2

Remove the values, you can directly use INSERT SELECT.

INSERT INTO T1 
            (ID_CUSTOMER, 
             ID_ENVIRONMENT) 
SELECT ID_CUSTOMER =(SELECT Max(id) 
                     FROM   customer 
                     WHERE  NAME = 'abc'), 
       ID_ENVIRONMENT = (SELECT Max(id) 
                         FROM   environment 
                         WHERE  NAME = 'xyz') 

The Max(id) here is to make sure the inner query returns a single value

Sign up to request clarification or add additional context in comments.

Comments

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.