0
Insert into xHH_QuickScan
(
    ScanID,
    EmployeeID,
    ProjectID,
    Barcode,
    Scandate,
    Scantime,
    ManualEntry,
    Category,
    Date1,
    Date2,
    Serial,
    Descrid,
    Date3,
    AssetID,
    Date4,
    AStatus,
    BarcodeNew,
    SerialNew,
    DescrNew
)
Values
(
/****** check DescID value ******/
if @AssetID = ''
    Begin
        Set @Descrid = ''
    End
Else
    Begin
         Set @Descrid = @Descrid
        END
End

    @ScanID,
    @EmployeeID,
    @ProjectID,
    @Barcode,
    @Scandate,
    @Scantime,
    @ManualEntry,
    @Category,
    @Date1,
    @Date2,
    @Serial,
    @Descrid,
    @Date3,
    @AssetID,
    @Date4,
    @AStatus,
    @BarcodeNew,
    @SerialNew,
    @DescrNew
)

这会引发错误。我也尝试过 CASE,但有错误。我需要测试@AssetID 的值并相应地更改@Descrid 的值

4

3 回答 3

3

是的,它会的。您不能在值语句中使用过程代码,因为它们不是值。

尝试

insert xHHQuickScan (ScanID, DescID, ... )
select 
      @ScanID,
      case Isnull(@assetID,'') = '' then ''
                  else @DescID 
      end, 
      ...
于 2013-10-14T17:33:47.493 回答
0

尝试这个:

Insert into xHH_QuickScan
    (
    ScanID,
    EmployeeID,
    ProjectID,
    Barcode,
    Scandate,
    Scantime,
    ManualEntry,
    Category,
    Date1,
    Date2,
    Serial,
    Descrid,
    Date3,
    AssetID,
    Date4,
    AStatus,
    BarcodeNew,
    SerialNew,
    DescrNew
    )
Values
    (
    @ScanID,
    @EmployeeID,
    @ProjectID,
    @Barcode,
    @Scandate,
    @Scantime,
    @ManualEntry,
    @Category,
    @Date1,
    @Date2,
    @Serial,
    (CASE WHEN @AssetID = '' THEN '' ELSE @Descrid END),
    @Date3,
    @AssetID,
    @Date4,
    @AStatus,
    @BarcodeNew,
    @SerialNew,
    @DescrNew
    )
于 2013-10-14T17:35:02.323 回答
0

就个人而言,我更喜欢这种方式。

/****** check DescID value ******/
if @AssetID = ''
    Begin
        Set @Descrid = ''
    End

Insert into xHH_QuickScan
(
    ScanID,
    EmployeeID,
    ProjectID,
    Barcode,
    Scandate,
    Scantime,
    ManualEntry,
    Category,
    Date1,
    Date2,
    Serial,
    Descrid,
    Date3,
    AssetID,
    Date4,
    AStatus,
    BarcodeNew,
    SerialNew,
    DescrNew
)
Values
(
    @ScanID,
    @EmployeeID,
    @ProjectID,
    @Barcode,
    @Scandate,
    @Scantime,
    @ManualEntry,
    @Category,
    @Date1,
    @Date2,
    @Serial,
    @Descrid,
    @Date3,
    @AssetID,
    @Date4,
    @AStatus,
    @BarcodeNew,
    @SerialNew,
    @DescrNew
    )
于 2013-10-14T17:35:21.750 回答