sql server 添加语句中,VALUES值需要从数据库中查询出来

时间:2022-10-30 11:12:35
INSERT INTO DEVICE_BIT_NUMBER
 (
 DEVICE_ID,
 CODE
 )
VALUES 
 (
 SELECT device_id,DEVICE_CODE FROM device_info WHERE device_code LIKE '%ZNZM%'
 )

提示出错,正确写法去掉“values”,如下:

INSERT INTO DEVICE_BIT_NUMBER
    (
    DEVICE_ID,
    CODE   
    )
SELECT 
    device_id, 
    device_code   
FROM device_info a WHERE a.device_code LIKE '%ZNZM%'