当我尝试运行我的存储过程时,我收到此错误,我已检查插入是否与select匹配,这在大多数情况下似乎是问题。据我所知他们匹配所以其他东西一定是错的。
提前致谢
错误:
Msg 213,Level 16,State 1,Procedure system_IncreaseCustomTariffs,Line 36
列名或提供的值数与表定义不匹配。
代码:
--This sp is used by doRateIncrease.exe
ALTER PROCEDURE [dbo].[system_IncreaseCustomTariffs]
@Increase money,
@ProgramType varchar(30),
@StartDate varchar(10) = NULL,
@StopDate varchar(10) = NULL,
@Exclude varchar(1024) = ''
AS
SET NOCOUNT ON
DECLARE @OldFreightId int, @CustFreightId int, @BillAcct int, @User varchar(30)
SET @User = 'Increase_' + Replace(Convert(varchar(10), GetDate(), 101),'/', '-')
--Delete existing tariffs
DECLARE C1 CURSOR FOR
SELECT CustFreightId
FROM CustFreightProgramMaster
WHERE ProgramType = @ProgramType and CreateUsr = @User
OPEN C1
FETCH NEXT FROM C1 INTO @CustFreightId
WHILE (@@FETCH_STATUS = 0)
BEGIN
EXECUTE delete_CustFreightProgramMaster @CustFreightId = @CustFreightId
FETCH NEXT FROM C1 INTO @CustFreightId
END
CLOSE C1
DEALLOCATE C1
--Load exclusion table
CREATE TABLE #Exclude (parseValue VARCHAR(100))
INSERT INTO #Exclude
SELECT *
FROM dbo.Parse (@Exclude, ',')
WHERE IsNull(parseValue,'') <> ''
--Get all active tariffs
DECLARE Increase CURSOR FOR
SELECT CustFreightId, BillAcct FROM CustFreightProgramMaster
WHERE ProgramType = @ProgramType
and Convert(varchar(10), GetDate(), 101) Between StartDate and StopDate
OPEN Increase
FETCH NEXT FROM Increase INTO @OldFreightId, @BillAcct
WHILE (@@FETCH_STATUS = 0)
BEGIN
--If BillAcct excluded from increase just extend stop date
IF EXISTS (SELECT * FROM #Exclude WHERE Cast(parseValue as int)= @BillAcct)
BEGIN
--Extend existing tariff to new stop date
UPDATE CustFreightProgramMaster
SET StopDate = @StopDate
WHERE CustFreightId = @OldFreightId
END
--Create new tariff
ELSE
BEGIN
--Expire existing tariff 1 day prior to start on new tariff
UPDATE CustFreightProgramMaster
SET StopDate = DateAdd(day, -1, @StartDate)
WHERE CustFreightId = @OldFreightId
--Create new program master
INSERT INTO CustFreightProgramMaster(BillAcct, ProgramType, BiDirect, StartDate, StopDate,
AbsoluteMinimum, MaxDiscount, MaxPalletWeight, CreateSvr, CreateTrm, CreateUsr, CreateDT)
SELECT BillAcct, ProgramType, BiDirect, @StartDate, @StopDate, AbsoluteMinimum,
MaxDiscount, MaxPalletWeight, CreateSvr, CreateTrm, @User, GetDate()
FROM CustFreightProgramMaster WHERE CustFreightId = @OldFreightId
--Get new FreightId
SET @CustFreightId = 0
SET @CustFreightId = SCOPE_IDENTITY()
IF IsNull(@CustFreightId,0) = 0
BEGIN
RAISERROR('Tariff not created.',16,1)
RETURN
END
--Copy Origin Zones
INSERT INTO CustFreightProgramOriginZones (CustFreightId, ZoneId, CreateSvr, CreateTrm, CreateUsr, CreateDT)
SELECT @CustFreightId, ZoneId, CreateSvr, CreateTrm, @User, GetDate()
FROM CustFreightProgramOriginZones WHERE CustFreightId = @OldFreightId
--Copy Destination Zones
INSERT INTO CustFreightProgramDestZones (CustFreightId, ZoneId, CreateSvr, CreateTrm, CreateUsr, CreateDT)
SELECT @CustFreightId, ZoneId, CreateSvr, CreateTrm, @User, GetDate()
FROM CustFreightProgramDestZones WHERE CustFreightId = @OldFreightId
--Update Customer Program Master program description
UPDATE CustFreightProgramMaster
SET ProgramDesc = dbo.BuildCustFreightProgramDesc(CustFreightId)
WHERE CustFreightId = @CustFreightId
--Copy weight breaks, apply increase
INSERT INTO CustFreightProgramWeightBreaks (CustFreightId, LowValue, HighValue, UnitCost, CreateSvr, CreateTrm, CreateUsr, CreateDT)
SELECT @CustFreightId, LowValue, HighValue, dbo.IncreaseUnitCost(@ProgramType, UnitCost, @Increase), CreateSvr, CreateTrm, @User, GetDate()
FROM CustFreightProgramWeightBreaks WHERE CustFreightId = @OldFreightId
--Copy pallet breaks, apply increase
INSERT INTO CustFreightProgramPalletRates (CustFreightId, LowValue, HighValue, UnitCost, CreateSvr, CreateTrm, CreateUsr, CreateDT)
SELECT @CustFreightId, LowValue, HighValue, dbo.IncreaseUnitCost(@ProgramType, UnitCost, @Increase), CreateSvr, CreateTrm, @User, GetDate()
FROM CustFreightProgramPalletRates WHERE CustFreightId = @OldFreightId
END
FETCH NEXT FROM Increase INTO @OldFreightId, @BillAcct
END
CLOSE Increase
DEALLOCATE Increase
--Clean up
DROP TABLE #Exclude
答案 0 :(得分:2)
看起来问题就在这里:
INSERT INTO #Exclude
SELECT * FROM dbo.Parse (@Exclude, ',')
WHERE IsNull(parseValue,'') <> ''
也许宁愿做到:
INSERT INTO #Exclude
SELECT [Value - Or name of first column] FROM dbo.Parse (@Exclude, ',')
WHERE IsNull(parseValue,'') <> ''