SQL Server version of MYSQL insert into
I have the following query running on a MySQL, but it fails when I run it on a SQL Server database. How should it look to please SQL Server?
开发者_如何转开发INSERT INTO first_table (pk, data)
VALUES ((SELECT value
FROM second_table
WHERE key = 'key'),
'other-data');
Something like this
INSERT INTO first_table (pk, data)
SELECT value ,
'other-data'
FROM second_table
WHERE key = 'key'
Have a look at INSERT
Load data using the SELECT and EXECUTE options
INSERT INTO first_table (pk, data)
SELECT value, 'other-data'
FROM second_table
WHERE key = 'key'
Try this:
INSERT INTO first_table (pk, data)
SELECT value, 'other-data'
FROM second_table
WHERE key = 'key';
INSERT INTO first_table (pk, data)
SELECT value, 'other-data'
FROM second_table
WHERE key = 'key'
You could use a subquery to retrieve the PK:
INSERT INTO first_table (pk, data)
SELECT
(SELECT value FROM second_table WHERE key = 'key')
, 'other-data'
精彩评论