D
D
Dmitrii -2015-08-20 14:54:40
SQL
Dmitrii -, 2015-08-20 14:54:40

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

2 answer(s)
D
Dmitry Kovalsky, 2015-08-20
@dmitryKovalskiy

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?

D
Dmitrii -, 2015-08-20
@Andermat

https://docs.google.com/spreadsheets/d/1E7H2Vj4NRR...
Here I have shown what the structure looks like

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question