Tasos Tasos - 1 year ago 70
SQL Question

Insert Into a table a variable outside of the SELECT results

I am working on a Stored Procedure on MSSQL. This is a simplified example of my case.

another code that has declared a variable @Country
INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers;

So, what I try to do is instead of the
value of the
, insert the
variable of the previous code, but keep the
from the results.

I wasn't able to find a similar question and trial and error didn't help.

Answer Source

Just use the variable instead:

Insert Into Customers (CustomerName, Country)
Select SupplierName, @Country 
From Suppliers;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download