Answer the question
In order to leave comments, you need to log in
How to write a query with INSERT in MS SQL?
UPD
The question was solved independently by a stupidly nested select:
INSERT INTO dbo.CouponOrderSources
(Location_Code, CouponCode, OrderSourceCode, IsVisible)
SELECT
(SELECT Location_Code FROM dbo.Location_Codes), '_INTSP1', 'INTERNET', '1'
The task is to write an INSERT query into a table, where the data in 1 field is substituted from the adjacent table, and the other 3 fields are substituted from the current one. None of the fields can be NULL.
I tried:
INSERT INTO [dbo].[CouponOrderSources]
(Location_Code, CouponCode, OrderSourceCode, IsVisible)
SELECT CouponCode, OrderSourceCode, IsVisible FROM [dbo].[CouponOrderSources]
WHERE CouponCode = '_INTSP1' and OrderSourceCode = 'INTERNET'
UNION All
SELECT Location_Code FROM [dbo].[Location_Codes]
But I don't fully understand the UNION syntax, it doesn't work.
Answer the question
In order to leave comments, you need to log in
You should make Join instead of union. Without a table structure, it's hard to tell, perhaps CROSS JOIN or FULL is needed. Are there fields to join?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question