Reputation: 3098
I am going to populate an intersection table with a value from another table (view), but I have one value which will be static for each insert.
My query looks like this:
INSERT INTO dbo.intersectiontable
(col1, col2)
SELECT *col3*, col4
FROM dbo.viewtable
WHERE *col3* is null
Now, col3 is the field that I need to switch out with a static value (eg. 11), how can I both insert from another table AND specify one static value?
My guess would be
INSERT INTO dbo.intersectiontable
(col1, col2)
VALUES
(11, (SELECT col4 FROM dbo.viewtable WHERE col3 is null))
But to me that doesn't quite look right.
Upvotes: 0
Views: 79
Reputation: 182
you can try this:
INSERT INTO dbo.intersectiontable(col1, col2) SELECT 11,col4 FROM dbo.viewtable WHERE col3 is null
Upvotes: 0
Reputation: 18737
Try this:
INSERT INTO dbo.intersectiontable (col1, col2) VALUES
(SELECT 11, col4 FROM dbo.viewtable WHERE col3 is null)
Upvotes: 0
Reputation: 8109
You can try like this...
INSERT INTO dbo.intersectiontable
(col1, col2)
SELECT 11, col4 FROM dbo.viewtable WHERE col3 is null
Upvotes: 2