SQL INSERT based on SELECT results

INSERT INTO table1
(
    f1, f2, f3, f4
)
SELECT f1, f2, f3, 'defaultval' as f4
FROM table2
WHERE value = 1

INSERT INTO table (field)
SELECT '1stString.' + cast(id as varchar(50)) + '.2ndString' 
FROM table2 
WHERE id = 10

Edit - response to comment: You're on the right track, but you want to select your hard-coded strings from your table, like this:

INSERT INTO table1 (field1, field2, field3)
SELECT '1stVal', '2ndVal', '1stString.' + cast(id as varchar(50)) + '.2ndString' 
FROM table2 
WHERE id = 10

This is also illustrated in Dustin Laine's answer.

Tags:

Sql

Insert