Tasos Tasos - 8 months ago 25
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.


Just use the variable instead:

Insert Into Customers (CustomerName, Country)
Select SupplierName, @Country 
From Suppliers;