UPDATE查询中的“SQL命令未正确结束”错误

时间:2013-01-31 18:27:08

标签: sql sql-server

我正在尝试在VB.NET代码中更新SQL Server表中的多行。但是,在我添加更多SELECT语句之前,我正专注于更新一行。我理解以下方法非常灵活,但是它抛出错误“SQL命令未正确结束”:

UPDATE ndcs 
SET    PACKAGE_TYPE_CODE = x.package_type_code, 
       PACKAGE_DESC = x.package_desc, 
       COMMENTS = x.comments 
FROM   hub_non_dcs_product_pkgtype ndcs 
       INNER JOIN (SELECT PRODUCT_ID = 'SEN0982_pdf_1', 
                          PACKAGE_TYPE_CODE = '', 
                          PACKAGE_DESC = '', 
                          COMMENTS = 'DPDC LITERATURE') x 
               ON x.product_id = ndcs.product_id 

我的语法有什么问题?

1 个答案:

答案 0 :(得分:1)

试试这个:

UPDATE ndcs 
SET (PACKAGE_TYPE_CODE, PACKAGE_DESC, COMMENTS )  = (
SELECT
    x.package_type_code, 
    x.package_desc, 
    x.comments 
FROM   
    hub_non_dcs_product_pkgtype ndcs 
    INNER JOIN (SELECT PRODUCT_ID = 'SEN0982_pdf_1', 
                      PACKAGE_TYPE_CODE = '', 
                      PACKAGE_DESC = '', 
                      COMMENTS = 'DPDC LITERATURE') x 
           ON x.product_id = ndcs.product_id 
)