0

我有 2 个具有相同列的表,例如 ID、SupplierID、ConditionValue、Status、Deleted,并且我在代码中插入数据

INSERT INTO SCM_SupplierShippingRateHistory  
SELECT *           
FROM SCM_SupplierShippingRate          
WHERE  Id NOT IN(SELECT ID FROM dbo.GetIDsTableFromIDsList(@NonDeleteShippingIDs))        
AND SupplierId= @SupplierID        
AND ConditionValue IS NULL    
AND Deleted=0     

我想插入相同的数据,但我想设置状态 =4 我该怎么做

4

2 回答 2

1

明确选择列。

INSERT INTO SCM_SupplierShippingRateHistory 
(
    Col1,
    Col2,
    .
    .
    .
    Status
) 
SELECT  Col1,
        Col2,
        .
        .
        .
        4 AS [Status]

FROM    SCM_SupplierShippingRate          
WHERE   Id NOT IN
        (
            SELECT ID 
            FROM   dbo.GetIDsTableFromIDsList(@NonDeleteShippingIDs)
        )        
        AND SupplierId= @SupplierID        
        AND ConditionValue IS NULL    
        AND Deleted=0     
于 2013-10-22T09:22:05.020 回答
0

你可以像这样设置状态。

INSERT INTO SCM_SupplierShippingRateHistory  
SELECT ID,SupplierID,ConditionValue,4 AS Status,Deleted           
FROM SCM_SupplierShippingRate          
WHERE  Id NOT IN(SELECT ID FROM dbo.GetIDsTableFromIDsList(@NonDeleteShippingIDs))        
AND SupplierId= @SupplierID        
AND ConditionValue IS NULL    
AND Deleted=0 
于 2013-10-22T09:23:33.370 回答