0

我有下面的代码。它基本上从由 asp.net 上传控件加载的电子表格中获取值。自动分配凭证编号。我将数据放入临时表中,然后从临时表中选择数据并将其插入到我的实际数据库表中。数据是分组的,因此它采用最小的文档编号和日期列(数据唯一不同的列)。数据加载正常,但由于某种原因它没有被分组。有没有人看到查询本身有任何问题?

    CREATE Procedure dbo.temptable
    (
        @DocumentBranchPlant varchar(12)
      , @DocumentType varchar(2)
      , @DEANumber varchar(9)
      , @DebitMemo varchar(25)
      , @DebitTotal float
      , @ErrorOverRide bit
      , @OnHold bit
      , @LastModifiedUser varchar(50)
      , @ResubmissionCode char(2)
      , @DocumentNumber float out 
    )

AS
begin

  declare @TransmissionDate datetime
  declare @JulianTransmissionDate numeric(18,0)
  declare @ShipTo float
  declare @CustomerName varchar(40)

  Set @DocumentNumber = scope_identity()
  set @TransmissionDate = getdate()
  set @JulianTransmissionDate =getdate()


  DECLARE @cb table
  ( DocumentBranchPlant     char(12)
  , DocumentNumber          float   
  , DocumentType            char(2)
  , JulianTransmissionDate  numeric(18,0)
  , TransmissionDate        datetime
  , DEANumber               varchar(9)
  , ShipTo                  float
  , DebitMemo               char(25)
  , DebitTotal              float   
  , CustomerName            varchar(40)
  , ErrorOverRide           bit
  , EntryComplete           bit 
  , OnHold                  bit
  , ManualEntry             bit
  , LastModifiedUser        varchar(50)
  , LastModifiedDate        datetime
  , ResubmissionCode        char(2))

  INSERT INTO @cb
  ( DocumentBranchPlant
  , DocumentNumber 
  , DocumentType 
  , JulianTransmissionDate
  , TransmissionDate
  , DEANumber
  , ShipTo
  , DebitMemo
  , DebitTotal
  , CustomerName
  , ErrorOverRide
  , EntryComplete
  , OnHold
  , ManualEntry
  , LastModifiedUser
  , LastModifiedDate
  , ResubmissionCode)
  VALUES
  ( @DocumentBranchPlant
  , @DocumentNumber
  , @DocumentType
  , @JulianTransmissionDate
  , @TransmissionDate
  , @DEANumber
  , @ShipTo
  , @DebitMemo
  , @DebitTotal
  , @CustomerName
  , @ErrorOverRide
  , 0
  , @OnHold
  , 1
  , @LastModifiedUser
  , getdate()
  , @ResubmissionCode)



  INSERT INTO dbo.CbTempTable
  ( DocumentBranchPlant
  , DocumentNumber
  , DocumentType
  , JulianTransmissionDate
  , TransmissionDate
  , DEANumber
  , ShipTo
  , DebitMemo
  , DebitTotal
  , CustomerName
  , ErrorOverRide
  , EntryComplete
  , OnHold
  , ManualEntry
  , LastModifiedUser
  , LastModifiedDate
  , ResubmissionCode)
  SELECT
    DocumentBranchPlant
  , min(DocumentNumber)
  , DocumentType
  , JulianTransmissionDate
  , min(TransmissionDate)
  , DEANumber
  , ShipTo
  , DebitMemo
  , DebitTotal
  , CustomerName
  , ErrorOverRide
  , EntryComplete
  , OnHold
  , ManualEntry
  , LastModifiedUser
  , min(LastModifiedDate)
  , ResubmissionCode
  FROM @cb

  GROUP BY
    DocumentBranchPlant
  , DocumentType
  , JulianTransmissionDate
  , DEANumber
  , ShipTo
  , DebitMemo
  , DebitTotal
  , CustomerName
  , ErrorOverRide
  , EntryComplete
  , OnHold
  , ManualEntry
  , LastModifiedUser
  , ResubmissionCode
4

0 回答 0