sqlsql-serversql-server-2008t-sql

Insert into select from SQL query with both query and static values


I am trying to perform insert query from one specific column from a table plus two static values, I am trying something like this:

INSERT INTO TableA(PolicyId, Type, Used)
SELECT ID FROM Policies, 'A', 1 

But I am getting error near 'A' per SSMSE. How can I tackle this task?


Solution

  • You'll need to put these static values in your SELECT clause:

    INSERT INTO TableA(PolicyId, Type, Used) SELECT ID, 'A', 1 FROM Policies