开发者

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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜