0
我遇到了此存儲過程的問題。我已經研究了幾次,所以我猜測我只是錯過了一些明顯的東西。如果我嘗試刪除選擇列表的任何部分,那麼SSMS會給我同樣的錯誤。如果我讓他們平等,然後VS調試給我的錯誤。我對這個有點困惑。大多數程序是如下 -INSERT語句的選擇列表包含比插入列表更多的項目
ALTER PROCEDURE [dbo].[Billing_Misc_Update_Test]
(
@ID as varchar(100), @CandidateID as varchar(100), @EntryType as varchar(100), @Amount as money, @EntryDate as smalldatetime, @InvoiceBillingDate as smalldatetime, @ClientKey as varchar(100), @BillingMemo as varchar(100), @UserID as varchar(100), @RegBilled as varchar(100), @OTBilled as varchar(100), @RegPaid as varchar(100), @OTPaid as varchar(100), @chkStatus as varchar(25) )
-- This is an insert
if @ID = 0
Begin
If not exists (select 1 from AccoutingReports with (nolock)
where Verify = @CandidateID
and BillingDate = @EntryDate
and InvoiceBillingDate = @InvoiceBillingDate
and BillingMiscType = @BillingMiscType
)
Begin
if @EntryType = 'Expense' or @EntryType = 'Bonus' or @EntryType = 'other'
Begin
Insert into AccoutingReports (
[BillingDate],
[ConsultantName],
[HoursWorked],
[OTHoursWork],
[HoursBilled],
[RegHoursBilled],
[OTHoursBilled],
[PayDollars],
[BilledDollars],
[RegBilledDollars],
[NegBilledDollars],
[OTBilledDollars],
[NegOTBilled_Dollars],
[MedicalCost],
[FicsSutaSS],
[PerDiem],
[PerDiemPay],
[COGS],
[GrossProfit],
[GrossMargin],
[CommissionPercent],
[CommissionSales],
[CommissionRecruiter],
[Verify],
[BurdenPercent],
[ClientKey],
[W1],
[W2],
[EarnedDays],
[VacationDays],
[Memo],
[TSDate],
[isImported],
[BillingMiscType],
[BillingMiscMemo],
[InvoiceBillingDate],
[InvoiceStatus])
Select
@EntryDate,
'Updated By UserID: ' + @UserID,
0,
0,
0,
0,
0,
@amount,
@amount,
@amount,
@amount,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
@CandidateID,
0,
@ClientKey,
0,
0,
0,
0,
@BillingMemo,
getdate(),
0,
@BillingMiscType,
@BillingMemo,
@InvoiceBillingDate,
@chkStatus
End Else
Begin
Insert into AccoutingReports (
[BillingDate],
[ConsultantName],
[HoursWorked],
[OTHoursWork],
[HoursBilled],
[RegHoursBilled],
[OTHoursBilled],
[PayDollars],
[BilledDollars],
[RegBilledDollars],
[NegBilledDollars],
[OTBilledDollars],
[NegOTBilled_Dollars],
[MedicalCost],
[FicsSutaSS],
[PerDiem],
[PerDiemPay],
[COGS],
[GrossProfit],
[GrossMargin],
[CommissionPercent],
[CommissionSales],
[CommissionRecruiter],
[Verify],
[BurdenPercent],
[ClientKey],
[W1],
[W2],
[EarnedDays],
[VacationDays],
[Memo],
[TSDate],
[isImported],
[BillingMiscType],
[BillingMiscMemo],
[InvoiceBillingDate],
[InvoiceStatus])
Select @EntryDate,
'Updated By UserID: ' + @UserID,
convert(money, @RegPaid) + convert(money, @OTPaid),
@OTPaid,
convert(money, @RegBilled) + convert(money, @OTBilled),
@RegBilled,
@OTBilled,
(convert(money, @RegPaid) * @payrate) + (convert(money, @OTPaid) + @PayRate),
(convert(money, @RegBilled) * @BillRate) + (convert(money, @OTBilled) + @BillRate),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
@CandidateID,
0,
@ClientKey,
0,
0,
0,
0,
@BillingMemo,
getdate(),
0,
@BillingMiscType,
@BillingMemo,
@InvoiceBillingDate,
@chkStatus
End
Select RowsUpdated = @@Rowcount, Error = 'New Entry: Transaction Successfull'
End Else
Begin
Select RowsUpdated = 0, Error = 'Entry Already Exists'
End
End Else
Begin
If not exists (select 1 from AccoutingReports with (nolock)
where Verify = @CandidateID
and BillingDate = @EntryDate
and InvoiceBillingDate = @InvoiceBillingDate
and BillingMiscType = @BillingMiscType
and ID <> @ID
)
Begin
if @EntryType = 'Expense' or @EntryType = 'Bonus' or @EntryType = 'other'
Begin
Update AccoutingReports
Set [BillingDate] = @EntryDate
, [ConsultantName] = 'Updated By UserID: ' + @UserID
, [HoursWorked] = 0
, [OTHoursWork] = 0
, [HoursBilled] = 0
, [RegHoursBilled] = 0
, [OTHoursBilled] = 0
, [PayDollars] = @amount
, [BilledDollars] = @amount
, [RegBilledDollars] = @amount
, [NegBilledDollars] = @amount
, BillingMiscType = @BillingMiscType
, BillingMiscMemo = @BillingMemo
, InvoiceBillingDate = @InvoiceBillingDate
, InvoiceStatus = @chkStatus
where ID = @ID
End Else
Begin
Update AccoutingReports
Set [BillingDate] = @EntryDate
, [ConsultantName] = 'Updated By UserID: ' + @UserID
, [HoursWorked] = convert(money, @RegPaid) + convert(money, @OTPaid)
, [OTHoursWork] = @OTPaid
, [HoursBilled] = convert(money, @RegBilled) + convert(money, @OTBilled)
, [RegHoursBilled] = @RegBilled
, [OTHoursBilled] = @OTBilled
, [PayDollars] = (convert(money, @RegPaid) * @payrate) + (convert(money, @OTPaid) + @PayRate)
, [BilledDollars] = (convert(money, @RegBilled) * @BillRate) + (convert(money, @OTBilled) + @BillRate)
, [RegBilledDollars] = 0
, [NegBilledDollars] = 0
, BillingMiscType = @BillingMiscType
, BillingMiscMemo = @BillingMemo
, InvoiceBillingDate = @InvoiceBillingDate
, InvoiceStatus = @chkStatus
where ID = @ID
End
Select RowsUpdated = @@Rowcount, Error = 'Update Entry: Transaction Successfull'
End Else
Begin
Select RowsUpdated = 0, Error = 'Entry Already Exists'
End
End
的ID通常導致到0,並且EntryType
我已經開始是獎金。所以它應該運行插入/選擇語句的第一塊,但是會出現錯誤。
值得注意的是,我所做的更改是將新列InvoiceStatus添加到表AccountingReports以存儲chkStatus作爲varchar(25)
。在將這個新列添加到表中並修改insert/select語句之後,它給了我這個錯誤。我很迷茫,所以任何建議都會有幫助,謝謝!
我看到的唯一問題是你的程序參數後需要'AS BEGIN ... SP Guts ... END' –
這裏只有兩條插入語句。將它們與您的程序分開並自行運行。一些體面的格式化將使調試變得更容易。當你將大量列的語句插入2行時,它會使調試和支持變得更加困難。 –
@ Dave.Gugg語法應該是準確的,因爲我只是修改了以前可以正常工作的SP。我只是試圖讓它適合堆棧溢出的灰色編碼框的要求。 – ASimonis01