gbzhhu
asked on
error converting data type nvarchar to numeric
Hi,
I am writing some XML data to tables using OPENXML. I have a problem writing to 1 table. The error I get is 'error converting data type nvarchar to numeric'. There is no nvarchar column in the table, only 1 int column and the rest are all numeric (18, 0). below is the stored procedure block that attempts to write to my table (bm_overheads) and the XML element holding the data. I hope someone can figure out where the error is coming from.
====== sproc block =========
-- Add to bm_overheads
INSERT INTO
bm_overheads
SELECT
@bmId AS bmId, FullTimeLabour, FullTimeLabourCC, FullTimeLabourCCPercent, PartTimeLabour, PartTimeLabourCC, PartTimeLabourCCPercent,
NumberOfPropriators, NotionalLabourCost, NotionalLabourCostCC, NotionalLabourCostCCPercen t, TotalLabourCost, TotalLabourCostCC,
OtherLabourCosts, MachineryDepn, MachineryRepairs, MachineryRepairsCC, MachineryRepairsCCPercent, VehicleRepairs, VehicleRepairsCC,
VehicleRepairsCCPercent, MachineryFuel, MachineryFuelCC, MachineryFuelCCPercent, VehicleFuel, VehicleFuelCC, VehicleFuelCCPercent,
Haulage, HaulageCC, HaulageCCPercent, GrainStorage, GrainStorageCC, GrainStorageCCPercent, ElectricAndGas, ElectricAndGasCC,
ElectricAndGasCCPercent, ContractStaff, ContractStaffCC, ContractStaffCCPercent, TotalMachineryCost, TotalMachineryCostCC,
OtherMachineryCosts, PropertyDepn, Repairs, RepairsCC, RepairsCCPercent, CouncilTax, CouncilTaxCC, CouncilTaxCCPercent, WaterRates,
WaterRatesCC, WaterRatesCCPercent, Drainage, DrainageCC, DrainageCCPercent, Lime, LimeCC, LimeCCPercent, PestControl, PestControlCC,
PestControlCCPercent, TotalPropertyCost, TotalPropertyCostCC, OtherPropertyCosts, InsuranceCosts, InsuranceCostsCC, InsuranceCostsCCPercent,
ProfessionalFees, ProfessionalFeesCC, ProfessionalFeesCCPercent, OtherAdminCosts, OtherAdminCostsCC, OtherAdminCostsCCPercent,
Subscriptions, SubscriptionsCC, SubscriptionsCCPercent, Miscellaneous, MiscellaneousCC, MiscellaneousCCPercent, SecretarialSupport,
SecretarialSupportCC, SecretarialSupportCCPercen t, TotalAdminCost, TotalAdminCostCC, OtherAdministrationCosts, AhaTenancies, AhaTenanciesCC,
AhaTenanciesCCPercent, FarmTenancies, FarmTenanciesCC, FarmTenanciesCCPercent, NoRentArea, NoRentAreaRent, NotionalRentCC, NotionalRentCCPercent,
TotalRentCost, TotalRentCostCC, OtherRentCosts, OverdraftInterest, OverdraftInterestCC, OverdraftInterestCCPercent , BankCharges,
BankChargesCC, BankChargesCCPercent, LoanInterest, LoanInterestCC, LoanInterestCCPercent, HpInterest, HpInterestCC, HpInterestCCPercent,
TotalFinanceCostCC, OtherFinanceCosts
FROM
OPENXML (@idoc, 'Benchmark/FarmDetails/Ove rheads', 2)
WITH (FullTimeLabour numeric (15, 2) 'FullTimeLabour',
FullTimeLabourCC numeric (15, 2) 'FullTimeLabourCC',
FullTimeLabourCCPercent numeric (15, 2) 'FullTimeLabourCCPercent',
PartTimeLabour numeric (15, 2) 'PartTimeLabour',
PartTimeLabourCC numeric (15, 2) 'PartTimeLabourCC',
PartTimeLabourCCPercent numeric (15, 2) 'PartTimeLabourCCPercent',
NumberOfPropriators numeric (15, 2) 'NumberOfPropriators',
NotionalLabourCost numeric (15, 2) 'NotionalLabourCost',
NotionalLabourCostCC numeric (15, 2) 'NotionalLabourCostCC',
NotionalLabourCostCCPercen t numeric (15, 2) 'NotionalLabourCostCCPerce nt',
TotalLabourCost numeric (15, 2) 'TotalLabourCost',
TotalLabourCostCC numeric (15, 2) 'TotalLabourCostCC',
OtherLabourCosts numeric (15, 2) 'OtherLabourCosts',
MachineryDepn numeric (15, 2) 'MachineryDepn',
MachineryRepairs numeric (15, 2) 'MachineryRepairs',
MachineryRepairsCC numeric (15, 2) 'MachineryRepairsCC',
MachineryRepairsCCPercent numeric (15, 2) 'MachineryRepairsCCPercent ',
VehicleRepairs numeric (15, 2) 'VehicleRepairs',
VehicleRepairsCC numeric (15, 2) 'VehicleRepairsCC',
VehicleRepairsCCPercent numeric (15, 2) 'VehicleRepairsCCPercent',
MachineryFuel numeric (15, 2) 'MachineryFuel',
MachineryFuelCC numeric (15, 2) 'MachineryFuelCC',
MachineryFuelCCPercent numeric (15, 2) 'MachineryFuelCCPercent',
VehicleFuel numeric (15, 2) 'VehicleFuel',
VehicleFuelCC numeric (15, 2) 'VehicleFuelCC',
VehicleFuelCCPercent numeric (15, 2) 'VehicleFuelCCPercent',
Haulage numeric (15, 2) 'Haulage',
HaulageCC numeric (15, 2) 'HaulageCC',
HaulageCCPercent numeric (15, 2) 'HaulageCCPercent',
GrainStorage numeric (15, 2) 'GrainStorage',
GrainStorageCC numeric (15, 2) 'GrainStorageCC',
GrainStorageCCPercent numeric (15, 2) 'GrainStorageCCPercent',
ElectricAndGas numeric (15, 2) 'ElectricAndGas',
ElectricAndGasCC numeric (15, 2) 'ElectricAndGasCC',
ElectricAndGasCCPercent numeric (15, 2) 'ElectricAndGasCCPercent',
ContractStaff numeric (15, 2) 'ContractStaff',
ContractStaffCC numeric (15, 2) 'ContractStaffCC',
ContractStaffCCPercent numeric (15, 2) 'ContractStaffCCPercent',
TotalMachineryCost numeric (15, 2) 'TotalMachineryCost',
TotalMachineryCostCC numeric (15, 2) 'TotalMachineryCostCC',
OtherMachineryCosts numeric (15, 2) 'OtherMachineryCosts',
PropertyDepn numeric (15, 2) 'PropertyDepn',
Repairs numeric (15, 2) 'Repairs',
RepairsCC numeric (15, 2) 'RepairsCC',
RepairsCCPercent numeric (15, 2) 'RepairsCCPercent',
CouncilTax numeric (15, 2) 'CouncilTax',
CouncilTaxCC numeric (15, 2) 'CouncilTaxCC',
CouncilTaxCCPercent numeric (15, 2) 'CouncilTaxCCPercent',
WaterRates numeric (15, 2) 'WaterRates',
WaterRatesCC numeric (15, 2) 'WaterRatesCC',
WaterRatesCCPercent numeric (15, 2) 'WaterRatesCCPercent',
Drainage numeric (15, 2) 'Drainage',
DrainageCC numeric (15, 2) 'DrainageCC',
DrainageCCPercent numeric (15, 2) 'DrainageCCPercent',
Lime numeric (15, 2) 'Lime',
LimeCC numeric (15, 2) 'LimeCC',
LimeCCPercent numeric (15, 2) 'LimeCCPercent',
PestControl numeric (15, 2) 'PestControl',
PestControlCC numeric (15, 2) 'PestControlCC',
PestControlCCPercent numeric (15, 2) 'PestControlCCPercent',
TotalPropertyCost numeric (15, 2) 'TotalPropertyCost',
TotalPropertyCostCC numeric (15, 2) 'TotalPropertyCostCC',
OtherPropertyCosts numeric (15, 2) 'OtherPropertyCosts',
InsuranceCosts numeric (15, 2) 'InsuranceCosts',
InsuranceCostsCC numeric (15, 2) 'InsuranceCostsCC',
InsuranceCostsCCPercent numeric (15, 2) 'InsuranceCostsCCPercent',
ProfessionalFees numeric (15, 2) 'ProfessionalFees',
ProfessionalFeesCC numeric (15, 2) 'ProfessionalFeesCC',
ProfessionalFeesCCPercent numeric (15, 2) 'ProfessionalFeesCCPercent ',
OtherAdminCosts numeric (15, 2) 'OtherAdminCosts',
OtherAdminCostsCC numeric (15, 2) 'OtherAdminCostsCC',
OtherAdminCostsCCPercent numeric (15, 2) 'OtherAdminCostsCCPercent' ,
Subscriptions numeric (15, 2) 'Subscriptions',
SubscriptionsCC numeric (15, 2) 'SubscriptionsCC',
SubscriptionsCCPercent numeric (15, 2) 'SubscriptionsCCPercent',
Miscellaneous numeric (15, 2) 'Miscellaneous',
MiscellaneousCC numeric (15, 2) 'MiscellaneousCC',
MiscellaneousCCPercent numeric (15, 2) 'MiscellaneousCCPercent',
SecretarialSupport numeric (15, 2) 'SecretarialSupport',
SecretarialSupportCC numeric (15, 2) 'SecretarialSupportCC',
SecretarialSupportCCPercen t numeric (15, 2) 'SecretarialSupportCCPerce nt',
TotalAdminCost numeric (15, 2) 'TotalAdminCost',
TotalAdminCostCC numeric (15, 2) 'TotalAdminCostCC',
OtherAdministrationCosts numeric (15, 2) 'OtherAdministrationCosts' ,
AhaTenancies numeric (15, 2) 'AhaTenancies',
AhaTenanciesCC numeric (15, 2) 'AhaTenanciesCC',
AhaTenanciesCCPercent numeric (15, 2) 'AhaTenanciesCCPercent',
FarmTenancies numeric (15, 2) 'FarmTenancies',
FarmTenanciesCC numeric (15, 2) 'FarmTenanciesCC',
FarmTenanciesCCPercent numeric (15, 2) 'FarmTenanciesCCPercent',
NoRentArea numeric (15, 2) 'NoRentArea',
NoRentAreaRent numeric (15, 2) 'NoRentAreaRent',
NotionalRentCC numeric (15, 2) 'NotionalRentCC',
NotionalRentCCPercent numeric (15, 2) 'NotionalRentCCPercent',
TotalRentCost numeric (15, 2) 'TotalRentCost',
TotalRentCostCC numeric (15, 2) 'TotalRentCostCC',
OtherRentCosts numeric (15, 2) 'OtherRentCosts',
OverdraftInterest numeric (15, 2) 'OverdraftInterest',
OverdraftInterestCC numeric (15, 2) 'OverdraftInterestCC',
OverdraftInterestCCPercent numeric (15, 2) 'OverdraftInterestCCPercen t',
BankCharges numeric (15, 2) 'BankCharges',
BankChargesCC numeric (15, 2) 'BankChargesCC',
BankChargesCCPercent numeric (15, 2) 'BankChargesCCPercent',
LoanInterest numeric (15, 2) 'LoanInterest',
LoanInterestCC numeric (15, 2) 'LoanInterestCC',
LoanInterestCCPercent numeric (15, 2) 'LoanInterestCCPercent',
HpInterest numeric (15, 2) 'HpInterest',
HpInterestCC numeric (15, 2) 'HpInterestCC',
HpInterestCCPercent numeric (15, 2) 'HpInterestCCPercent',
TotalFinanceCostCC numeric (15, 2) 'TotalFinanceCostCC',
OtherFinanceCosts numeric (15, 2) 'OtherFinanceCosts')
====== XML element =========
<Overheads>
<FullTimeLabour>0</FullTim eLabour>
<FullTimeLabourCC>0</FullT imeLabourC C>
<FullTimeLabourCCPercent>0 </FullTime LabourCCPe rcent>
<PartTimeLabour>0</PartTim eLabour>
<PartTimeLabourCC>0</PartT imeLabourC C>
<PartTimeLabourCCPercent>0 </PartTime LabourCCPe rcent>
<NumberOfPropriators>0</Nu mberOfProp riators>
<NotionalLabourCost>0</Not ionalLabou rCost>
<NotionalLabourCostCC>0</N otionalLab ourCostCC>
<NotionalLabourCostCCPerce nt>0</Noti onalLabour CostCCPerc ent>
<TotalLabourCost>0</TotalL abourCost>
<TotalLabourCostCC>0</Tota lLabourCos tCC>
<OtherLabourCosts />
<MachineryDepn>0</Machiner yDepn>
<MachineryRepairs>0</Machi neryRepair s>
<MachineryRepairsCC>0</Mac hineryRepa irsCC>
<MachineryRepairsCCPercent >0</Machin eryRepairs CCPercent>
<VehicleRepairs>0</Vehicle Repairs>
<VehicleRepairsCC>0</Vehic leRepairsC C>
<VehicleRepairsCCPercent>0 </VehicleR epairsCCPe rcent>
<MachineryFuel>0</Machiner yFuel>
<MachineryFuelCC>0</Machin eryFuelCC>
<MachineryFuelCCPercent>0< /Machinery FuelCCPerc ent>
<VehicleFuel>0</VehicleFue l>
<VehicleFuelCC>0</VehicleF uelCC>
<VehicleFuelCCPercent>0</V ehicleFuel CCPercent>
<Haulage>0</Haulage>
<HaulageCC>0</HaulageCC>
<HaulageCCPercent>0</Haula geCCPercen t>
<GrainStorage>0</GrainStor age>
<GrainStorageCC>0</GrainSt orageCC>
<GrainStorageCCPercent>0</ GrainStora geCCPercen t>
<ElectricAndGas>0</Electri cAndGas>
<ElectricAndGasCC>0</Elect ricAndGasC C>
<ElectricAndGasCCPercent>0 </Electric AndGasCCPe rcent>
<ContractStaff>0</Contract Staff>
<ContractStaffCC>0</Contra ctStaffCC>
<ContractStaffCCPercent>0< /ContractS taffCCPerc ent>
<TotalMachineryCost>0</Tot alMachiner yCost>
<TotalMachineryCostCC>0</T otalMachin eryCostCC>
<OtherMachineryCosts />
<MachineryDepreciation>
<CurrentYear>0</CurrentYea r>
<Expanded>false</Expanded>
<Machines>
<DepreciationBase>
<Index>0</Index>
<Description>Car 1</Description>
<PurchasedValue>2000.00</P urchasedVa lue>
<PurchasedYear>1998</Purch asedYear>
<DepnRatePercent>0.2</Depn RatePercen t>
<StartOfYearValue>419.43</ StartOfYea rValue>
<CurrentYearDepn>83.89</Cu rrentYearD epn>
<EndOfYearValue>335.54</En dOfYearVal ue>
<CcDepnPercent>0.1</CcDepn Percent>
<CurrentYearCCDepn>8.39</C urrentYear CCDepn>
<CcCurrentYearAverageCapit al>37.75</ CcCurrentY earAverage Capital>
</DepreciationBase>
<DepreciationBase>
<Index>1</Index>
<Description>Car 2</Description>
<PurchasedValue>7800</Purc hasedValue >
<PurchasedYear>2003</Purch asedYear>
<DepnRatePercent>0.12</Dep nRatePerce nt>
<StartOfYearValue>6040.32< /StartOfYe arValue>
<CurrentYearDepn>724.84</C urrentYear Depn>
<EndOfYearValue>5315.48</E ndOfYearVa lue>
<CcDepnPercent>0.04</CcDep nPercent>
<CurrentYearCCDepn>28.99</ CurrentYea rCCDepn>
<CcCurrentYearAverageCapit al>227.12< /CcCurrent YearAverag eCapital>
</DepreciationBase>
</Machines>
</MachineryDepreciation>
<PropertyDepn>0</PropertyD epn>
<Repairs>0</Repairs>
<RepairsCC>0</RepairsCC>
<RepairsCCPercent>0</Repai rsCCPercen t>
<CouncilTax>0</CouncilTax>
<CouncilTaxCC>0</CouncilTa xCC>
<CouncilTaxCCPercent>0</Co uncilTaxCC Percent>
<WaterRates>0</WaterRates>
<WaterRatesCC>0</WaterRate sCC>
<WaterRatesCCPercent>0</Wa terRatesCC Percent>
<Drainage>0</Drainage>
<DrainageCC>0</DrainageCC>
<DrainageCCPercent>0</Drai nageCCPerc ent>
<Lime>0</Lime>
<LimeCC>0</LimeCC>
<LimeCCPercent>0</LimeCCPe rcent>
<PestControl>0</PestContro l>
<PestControlCC>0</PestCont rolCC>
<PestControlCCPercent>0</P estControl CCPercent>
<TotalPropertyCost>0</Tota lPropertyC ost>
<TotalPropertyCostCC>0</To talPropert yCostCC>
<OtherPropertyCosts />
<PropertyDepreciation>
<CurrentYear>0</CurrentYea r>
<Expanded>false</Expanded>
<Properties>
<DepreciationBase>
<Index>0</Index>
<Description>House</Descri ption>
<PurchasedValue>10000</Pur chasedValu e>
<PurchasedYear>2001</Purch asedYear>
<DepnRatePercent>0.11</Dep nRatePerce nt>
<StartOfYearValue>6274.22< /StartOfYe arValue>
<CurrentYearDepn>690.16</C urrentYear Depn>
<EndOfYearValue>5584.06</E ndOfYearVa lue>
<CcDepnPercent>0.12</CcDep nPercent>
<CurrentYearCCDepn>82.82</ CurrentYea rCCDepn>
<CcCurrentYearAverageCapit al>711.50< /CcCurrent YearAverag eCapital>
</DepreciationBase>
<DepreciationBase>
<Index>1</Index>
<Description>House 2</Description>
<PurchasedValue>0</Purchas edValue>
<PurchasedYear>0</Purchase dYear>
<DepnRatePercent>0</DepnRa tePercent>
<StartOfYearValue>0</Start OfYearValu e>
<CurrentYearDepn>0</Curren tYearDepn>
<EndOfYearValue>0</EndOfYe arValue>
<CcDepnPercent>0</CcDepnPe rcent>
<CurrentYearCCDepn>0</Curr entYearCCD epn>
<CcCurrentYearAverageCapit al>0</CcCu rrentYearA verageCapi tal>
</DepreciationBase>
</Properties>
</PropertyDepreciation>
<InsuranceCosts>0</Insuran ceCosts>
<InsuranceCostsCC>0</Insur anceCostsC C>
<InsuranceCostsCCPercent>0 </Insuranc eCostsCCPe rcent>
<ProfessionalFees>0</Profe ssionalFee s>
<ProfessionalFeesCC>0</Pro fessionalF eesCC>
<ProfessionalFeesCCPercent >0</Profes sionalFees CCPercent>
<OtherAdminCosts>0</OtherA dminCosts>
<OtherAdminCostsCC>0</Othe rAdminCost sCC>
<OtherAdminCostsCCPercent> 0</OtherAd minCostsCC Percent>
<Subscriptions>0</Subscrip tions>
<SubscriptionsCC>0</Subscr iptionsCC>
<SubscriptionsCCPercent>0< /Subscript ionsCCPerc ent>
<Miscellaneous>0</Miscella neous>
<MiscellaneousCC>0</Miscel laneousCC>
<MiscellaneousCCPercent>0< /Miscellan eousCCPerc ent>
<SecretarialSupport>0</Sec retarialSu pport>
<SecretarialSupportCC>0</S ecretarial SupportCC>
<SecretarialSupportCCPerce nt>0</Secr etarialSup portCCPerc ent>
<TotalAdminCost>0</TotalAd minCost>
<TotalAdminCostCC>0</Total AdminCostC C>
<OtherAdministrationCosts />
<AhaTenancies>0</AhaTenanc ies>
<AhaTenanciesCC>0</AhaTena nciesCC>
<AhaTenanciesCCPercent>0</ AhaTenanci esCCPercen t>
<FarmTenancies>0</FarmTena ncies>
<FarmTenanciesCC>0</FarmTe nanciesCC>
<FarmTenanciesCCPercent>0< /FarmTenan ciesCCPerc ent>
<NoRentArea>0</NoRentArea>
<NoRentAreaRent>0</NoRentA reaRent>
<NotionalRentCC>0</Notiona lRentCC>
<NotionalRentCCPercent>0</ NotionalRe ntCCPercen t>
<TotalRentCost>0</TotalRen tCost>
<TotalRentCostCC>0</TotalR entCostCC>
<OtherRentCosts />
<OverdraftInterest>0</Over draftInter est>
<OverdraftInterestCC>0</Ov erdraftInt erestCC>
<OverdraftInterestCCPercen t>0</Overd raftIntere stCCPercen t>
<BankCharges>0</BankCharge s>
<BankChargesCC>0</BankChar gesCC>
<BankChargesCCPercent>0</B ankCharges CCPercent>
<LoanInterest>0</LoanInter est>
<LoanInterestCC>0</LoanInt erestCC>
<LoanInterestCCPercent>0</ LoanIntere stCCPercen t>
<HpInterest>0</HpInterest>
<HpInterestCC>0</HpInteres tCC>
<HpInterestCCPercent>0</Hp InterestCC Percent>
<TotalFinanceCostCC>0</Tot alFinanceC ostCC>
<OtherFinanceCosts />
</Overheads>
I am writing some XML data to tables using OPENXML. I have a problem writing to 1 table. The error I get is 'error converting data type nvarchar to numeric'. There is no nvarchar column in the table, only 1 int column and the rest are all numeric (18, 0). below is the stored procedure block that attempts to write to my table (bm_overheads) and the XML element holding the data. I hope someone can figure out where the error is coming from.
====== sproc block =========
-- Add to bm_overheads
INSERT INTO
bm_overheads
SELECT
@bmId AS bmId, FullTimeLabour, FullTimeLabourCC, FullTimeLabourCCPercent, PartTimeLabour, PartTimeLabourCC, PartTimeLabourCCPercent,
NumberOfPropriators, NotionalLabourCost, NotionalLabourCostCC, NotionalLabourCostCCPercen
OtherLabourCosts, MachineryDepn, MachineryRepairs, MachineryRepairsCC, MachineryRepairsCCPercent,
VehicleRepairsCCPercent, MachineryFuel, MachineryFuelCC, MachineryFuelCCPercent, VehicleFuel, VehicleFuelCC, VehicleFuelCCPercent,
Haulage, HaulageCC, HaulageCCPercent, GrainStorage, GrainStorageCC, GrainStorageCCPercent, ElectricAndGas, ElectricAndGasCC,
ElectricAndGasCCPercent, ContractStaff, ContractStaffCC, ContractStaffCCPercent, TotalMachineryCost, TotalMachineryCostCC,
OtherMachineryCosts, PropertyDepn, Repairs, RepairsCC, RepairsCCPercent, CouncilTax, CouncilTaxCC, CouncilTaxCCPercent, WaterRates,
WaterRatesCC, WaterRatesCCPercent, Drainage, DrainageCC, DrainageCCPercent, Lime, LimeCC, LimeCCPercent, PestControl, PestControlCC,
PestControlCCPercent, TotalPropertyCost, TotalPropertyCostCC, OtherPropertyCosts, InsuranceCosts, InsuranceCostsCC, InsuranceCostsCCPercent,
ProfessionalFees, ProfessionalFeesCC, ProfessionalFeesCCPercent,
Subscriptions, SubscriptionsCC, SubscriptionsCCPercent, Miscellaneous, MiscellaneousCC, MiscellaneousCCPercent, SecretarialSupport,
SecretarialSupportCC, SecretarialSupportCCPercen
AhaTenanciesCCPercent, FarmTenancies, FarmTenanciesCC, FarmTenanciesCCPercent, NoRentArea, NoRentAreaRent, NotionalRentCC, NotionalRentCCPercent,
TotalRentCost, TotalRentCostCC, OtherRentCosts, OverdraftInterest, OverdraftInterestCC, OverdraftInterestCCPercent
BankChargesCC, BankChargesCCPercent, LoanInterest, LoanInterestCC, LoanInterestCCPercent, HpInterest, HpInterestCC, HpInterestCCPercent,
TotalFinanceCostCC, OtherFinanceCosts
FROM
OPENXML (@idoc, 'Benchmark/FarmDetails/Ove
WITH (FullTimeLabour numeric (15, 2) 'FullTimeLabour',
FullTimeLabourCC numeric (15, 2) 'FullTimeLabourCC',
FullTimeLabourCCPercent numeric (15, 2) 'FullTimeLabourCCPercent',
PartTimeLabour numeric (15, 2) 'PartTimeLabour',
PartTimeLabourCC numeric (15, 2) 'PartTimeLabourCC',
PartTimeLabourCCPercent numeric (15, 2) 'PartTimeLabourCCPercent',
NumberOfPropriators numeric (15, 2) 'NumberOfPropriators',
NotionalLabourCost numeric (15, 2) 'NotionalLabourCost',
NotionalLabourCostCC numeric (15, 2) 'NotionalLabourCostCC',
NotionalLabourCostCCPercen
TotalLabourCost numeric (15, 2) 'TotalLabourCost',
TotalLabourCostCC numeric (15, 2) 'TotalLabourCostCC',
OtherLabourCosts numeric (15, 2) 'OtherLabourCosts',
MachineryDepn numeric (15, 2) 'MachineryDepn',
MachineryRepairs numeric (15, 2) 'MachineryRepairs',
MachineryRepairsCC numeric (15, 2) 'MachineryRepairsCC',
MachineryRepairsCCPercent numeric (15, 2) 'MachineryRepairsCCPercent
VehicleRepairs numeric (15, 2) 'VehicleRepairs',
VehicleRepairsCC numeric (15, 2) 'VehicleRepairsCC',
VehicleRepairsCCPercent numeric (15, 2) 'VehicleRepairsCCPercent',
MachineryFuel numeric (15, 2) 'MachineryFuel',
MachineryFuelCC numeric (15, 2) 'MachineryFuelCC',
MachineryFuelCCPercent numeric (15, 2) 'MachineryFuelCCPercent',
VehicleFuel numeric (15, 2) 'VehicleFuel',
VehicleFuelCC numeric (15, 2) 'VehicleFuelCC',
VehicleFuelCCPercent numeric (15, 2) 'VehicleFuelCCPercent',
Haulage numeric (15, 2) 'Haulage',
HaulageCC numeric (15, 2) 'HaulageCC',
HaulageCCPercent numeric (15, 2) 'HaulageCCPercent',
GrainStorage numeric (15, 2) 'GrainStorage',
GrainStorageCC numeric (15, 2) 'GrainStorageCC',
GrainStorageCCPercent numeric (15, 2) 'GrainStorageCCPercent',
ElectricAndGas numeric (15, 2) 'ElectricAndGas',
ElectricAndGasCC numeric (15, 2) 'ElectricAndGasCC',
ElectricAndGasCCPercent numeric (15, 2) 'ElectricAndGasCCPercent',
ContractStaff numeric (15, 2) 'ContractStaff',
ContractStaffCC numeric (15, 2) 'ContractStaffCC',
ContractStaffCCPercent numeric (15, 2) 'ContractStaffCCPercent',
TotalMachineryCost numeric (15, 2) 'TotalMachineryCost',
TotalMachineryCostCC numeric (15, 2) 'TotalMachineryCostCC',
OtherMachineryCosts numeric (15, 2) 'OtherMachineryCosts',
PropertyDepn numeric (15, 2) 'PropertyDepn',
Repairs numeric (15, 2) 'Repairs',
RepairsCC numeric (15, 2) 'RepairsCC',
RepairsCCPercent numeric (15, 2) 'RepairsCCPercent',
CouncilTax numeric (15, 2) 'CouncilTax',
CouncilTaxCC numeric (15, 2) 'CouncilTaxCC',
CouncilTaxCCPercent numeric (15, 2) 'CouncilTaxCCPercent',
WaterRates numeric (15, 2) 'WaterRates',
WaterRatesCC numeric (15, 2) 'WaterRatesCC',
WaterRatesCCPercent numeric (15, 2) 'WaterRatesCCPercent',
Drainage numeric (15, 2) 'Drainage',
DrainageCC numeric (15, 2) 'DrainageCC',
DrainageCCPercent numeric (15, 2) 'DrainageCCPercent',
Lime numeric (15, 2) 'Lime',
LimeCC numeric (15, 2) 'LimeCC',
LimeCCPercent numeric (15, 2) 'LimeCCPercent',
PestControl numeric (15, 2) 'PestControl',
PestControlCC numeric (15, 2) 'PestControlCC',
PestControlCCPercent numeric (15, 2) 'PestControlCCPercent',
TotalPropertyCost numeric (15, 2) 'TotalPropertyCost',
TotalPropertyCostCC numeric (15, 2) 'TotalPropertyCostCC',
OtherPropertyCosts numeric (15, 2) 'OtherPropertyCosts',
InsuranceCosts numeric (15, 2) 'InsuranceCosts',
InsuranceCostsCC numeric (15, 2) 'InsuranceCostsCC',
InsuranceCostsCCPercent numeric (15, 2) 'InsuranceCostsCCPercent',
ProfessionalFees numeric (15, 2) 'ProfessionalFees',
ProfessionalFeesCC numeric (15, 2) 'ProfessionalFeesCC',
ProfessionalFeesCCPercent numeric (15, 2) 'ProfessionalFeesCCPercent
OtherAdminCosts numeric (15, 2) 'OtherAdminCosts',
OtherAdminCostsCC numeric (15, 2) 'OtherAdminCostsCC',
OtherAdminCostsCCPercent numeric (15, 2) 'OtherAdminCostsCCPercent'
Subscriptions numeric (15, 2) 'Subscriptions',
SubscriptionsCC numeric (15, 2) 'SubscriptionsCC',
SubscriptionsCCPercent numeric (15, 2) 'SubscriptionsCCPercent',
Miscellaneous numeric (15, 2) 'Miscellaneous',
MiscellaneousCC numeric (15, 2) 'MiscellaneousCC',
MiscellaneousCCPercent numeric (15, 2) 'MiscellaneousCCPercent',
SecretarialSupport numeric (15, 2) 'SecretarialSupport',
SecretarialSupportCC numeric (15, 2) 'SecretarialSupportCC',
SecretarialSupportCCPercen
TotalAdminCost numeric (15, 2) 'TotalAdminCost',
TotalAdminCostCC numeric (15, 2) 'TotalAdminCostCC',
OtherAdministrationCosts numeric (15, 2) 'OtherAdministrationCosts'
AhaTenancies numeric (15, 2) 'AhaTenancies',
AhaTenanciesCC numeric (15, 2) 'AhaTenanciesCC',
AhaTenanciesCCPercent numeric (15, 2) 'AhaTenanciesCCPercent',
FarmTenancies numeric (15, 2) 'FarmTenancies',
FarmTenanciesCC numeric (15, 2) 'FarmTenanciesCC',
FarmTenanciesCCPercent numeric (15, 2) 'FarmTenanciesCCPercent',
NoRentArea numeric (15, 2) 'NoRentArea',
NoRentAreaRent numeric (15, 2) 'NoRentAreaRent',
NotionalRentCC numeric (15, 2) 'NotionalRentCC',
NotionalRentCCPercent numeric (15, 2) 'NotionalRentCCPercent',
TotalRentCost numeric (15, 2) 'TotalRentCost',
TotalRentCostCC numeric (15, 2) 'TotalRentCostCC',
OtherRentCosts numeric (15, 2) 'OtherRentCosts',
OverdraftInterest numeric (15, 2) 'OverdraftInterest',
OverdraftInterestCC numeric (15, 2) 'OverdraftInterestCC',
OverdraftInterestCCPercent
BankCharges numeric (15, 2) 'BankCharges',
BankChargesCC numeric (15, 2) 'BankChargesCC',
BankChargesCCPercent numeric (15, 2) 'BankChargesCCPercent',
LoanInterest numeric (15, 2) 'LoanInterest',
LoanInterestCC numeric (15, 2) 'LoanInterestCC',
LoanInterestCCPercent numeric (15, 2) 'LoanInterestCCPercent',
HpInterest numeric (15, 2) 'HpInterest',
HpInterestCC numeric (15, 2) 'HpInterestCC',
HpInterestCCPercent numeric (15, 2) 'HpInterestCCPercent',
TotalFinanceCostCC numeric (15, 2) 'TotalFinanceCostCC',
OtherFinanceCosts numeric (15, 2) 'OtherFinanceCosts')
====== XML element =========
<Overheads>
<FullTimeLabour>0</FullTim
<FullTimeLabourCC>0</FullT
<FullTimeLabourCCPercent>0
<PartTimeLabour>0</PartTim
<PartTimeLabourCC>0</PartT
<PartTimeLabourCCPercent>0
<NumberOfPropriators>0</Nu
<NotionalLabourCost>0</Not
<NotionalLabourCostCC>0</N
<NotionalLabourCostCCPerce
<TotalLabourCost>0</TotalL
<TotalLabourCostCC>0</Tota
<OtherLabourCosts />
<MachineryDepn>0</Machiner
<MachineryRepairs>0</Machi
<MachineryRepairsCC>0</Mac
<MachineryRepairsCCPercent
<VehicleRepairs>0</Vehicle
<VehicleRepairsCC>0</Vehic
<VehicleRepairsCCPercent>0
<MachineryFuel>0</Machiner
<MachineryFuelCC>0</Machin
<MachineryFuelCCPercent>0<
<VehicleFuel>0</VehicleFue
<VehicleFuelCC>0</VehicleF
<VehicleFuelCCPercent>0</V
<Haulage>0</Haulage>
<HaulageCC>0</HaulageCC>
<HaulageCCPercent>0</Haula
<GrainStorage>0</GrainStor
<GrainStorageCC>0</GrainSt
<GrainStorageCCPercent>0</
<ElectricAndGas>0</Electri
<ElectricAndGasCC>0</Elect
<ElectricAndGasCCPercent>0
<ContractStaff>0</Contract
<ContractStaffCC>0</Contra
<ContractStaffCCPercent>0<
<TotalMachineryCost>0</Tot
<TotalMachineryCostCC>0</T
<OtherMachineryCosts />
<MachineryDepreciation>
<CurrentYear>0</CurrentYea
<Expanded>false</Expanded>
<Machines>
<DepreciationBase>
<Index>0</Index>
<Description>Car 1</Description>
<PurchasedValue>2000.00</P
<PurchasedYear>1998</Purch
<DepnRatePercent>0.2</Depn
<StartOfYearValue>419.43</
<CurrentYearDepn>83.89</Cu
<EndOfYearValue>335.54</En
<CcDepnPercent>0.1</CcDepn
<CurrentYearCCDepn>8.39</C
<CcCurrentYearAverageCapit
</DepreciationBase>
<DepreciationBase>
<Index>1</Index>
<Description>Car 2</Description>
<PurchasedValue>7800</Purc
<PurchasedYear>2003</Purch
<DepnRatePercent>0.12</Dep
<StartOfYearValue>6040.32<
<CurrentYearDepn>724.84</C
<EndOfYearValue>5315.48</E
<CcDepnPercent>0.04</CcDep
<CurrentYearCCDepn>28.99</
<CcCurrentYearAverageCapit
</DepreciationBase>
</Machines>
</MachineryDepreciation>
<PropertyDepn>0</PropertyD
<Repairs>0</Repairs>
<RepairsCC>0</RepairsCC>
<RepairsCCPercent>0</Repai
<CouncilTax>0</CouncilTax>
<CouncilTaxCC>0</CouncilTa
<CouncilTaxCCPercent>0</Co
<WaterRates>0</WaterRates>
<WaterRatesCC>0</WaterRate
<WaterRatesCCPercent>0</Wa
<Drainage>0</Drainage>
<DrainageCC>0</DrainageCC>
<DrainageCCPercent>0</Drai
<Lime>0</Lime>
<LimeCC>0</LimeCC>
<LimeCCPercent>0</LimeCCPe
<PestControl>0</PestContro
<PestControlCC>0</PestCont
<PestControlCCPercent>0</P
<TotalPropertyCost>0</Tota
<TotalPropertyCostCC>0</To
<OtherPropertyCosts />
<PropertyDepreciation>
<CurrentYear>0</CurrentYea
<Expanded>false</Expanded>
<Properties>
<DepreciationBase>
<Index>0</Index>
<Description>House</Descri
<PurchasedValue>10000</Pur
<PurchasedYear>2001</Purch
<DepnRatePercent>0.11</Dep
<StartOfYearValue>6274.22<
<CurrentYearDepn>690.16</C
<EndOfYearValue>5584.06</E
<CcDepnPercent>0.12</CcDep
<CurrentYearCCDepn>82.82</
<CcCurrentYearAverageCapit
</DepreciationBase>
<DepreciationBase>
<Index>1</Index>
<Description>House 2</Description>
<PurchasedValue>0</Purchas
<PurchasedYear>0</Purchase
<DepnRatePercent>0</DepnRa
<StartOfYearValue>0</Start
<CurrentYearDepn>0</Curren
<EndOfYearValue>0</EndOfYe
<CcDepnPercent>0</CcDepnPe
<CurrentYearCCDepn>0</Curr
<CcCurrentYearAverageCapit
</DepreciationBase>
</Properties>
</PropertyDepreciation>
<InsuranceCosts>0</Insuran
<InsuranceCostsCC>0</Insur
<InsuranceCostsCCPercent>0
<ProfessionalFees>0</Profe
<ProfessionalFeesCC>0</Pro
<ProfessionalFeesCCPercent
<OtherAdminCosts>0</OtherA
<OtherAdminCostsCC>0</Othe
<OtherAdminCostsCCPercent>
<Subscriptions>0</Subscrip
<SubscriptionsCC>0</Subscr
<SubscriptionsCCPercent>0<
<Miscellaneous>0</Miscella
<MiscellaneousCC>0</Miscel
<MiscellaneousCCPercent>0<
<SecretarialSupport>0</Sec
<SecretarialSupportCC>0</S
<SecretarialSupportCCPerce
<TotalAdminCost>0</TotalAd
<TotalAdminCostCC>0</Total
<OtherAdministrationCosts />
<AhaTenancies>0</AhaTenanc
<AhaTenanciesCC>0</AhaTena
<AhaTenanciesCCPercent>0</
<FarmTenancies>0</FarmTena
<FarmTenanciesCC>0</FarmTe
<FarmTenanciesCCPercent>0<
<NoRentArea>0</NoRentArea>
<NoRentAreaRent>0</NoRentA
<NotionalRentCC>0</Notiona
<NotionalRentCCPercent>0</
<TotalRentCost>0</TotalRen
<TotalRentCostCC>0</TotalR
<OtherRentCosts />
<OverdraftInterest>0</Over
<OverdraftInterestCC>0</Ov
<OverdraftInterestCCPercen
<BankCharges>0</BankCharge
<BankChargesCC>0</BankChar
<BankChargesCCPercent>0</B
<LoanInterest>0</LoanInter
<LoanInterestCC>0</LoanInt
<LoanInterestCCPercent>0</
<HpInterest>0</HpInterest>
<HpInterestCC>0</HpInteres
<HpInterestCCPercent>0</Hp
<TotalFinanceCostCC>0</Tot
<OtherFinanceCosts />
</Overheads>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you're trying to push a nvarchar value into a numeric field...
ASKER
PErdu
Error suggests that, but my data contains only numeric values
Nightman,
I am leaving empty properties empty, is this seen as string data? I am putting default value for all column to 0 now and see what happens
Error suggests that, but my data contains only numeric values
Nightman,
I am leaving empty properties empty, is this seen as string data? I am putting default value for all column to 0 now and see what happens
ASKER
I have given default value of 0 to all columns and also changed the stored procedure for the columns that can be blank like this
In the select statement
OtherPropertyCosts = isnull(OtherPropertyCosts, 0)
instead of
OtherPropertyCosts
This has not solved the problem.
Other ideas please.
Thanks
H
In the select statement
OtherPropertyCosts = isnull(OtherPropertyCosts,
instead of
OtherPropertyCosts
This has not solved the problem.
Other ideas please.
Thanks
H
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, This was suggested by Nightman earlier. I haven't modified the XML, I tried the modify the stored procedure which didn't help. I will try to modify m,y program that generates the XML to insert 0 if no values exist for an element
Thanks
Thanks
ASKER
gpompe,
Yep, that worked. It was a big mistake on my part. Elements OtherLabourCosts, OtherMachineryCosts, ... OtherxxxxxxCosts are arrays!!! They didn't have array elements (0 lenght). I removed then from the stored procedure code. I will have to deal with them separately, maybe write them to a seperate table and associate them with the bm_overheads table
Thank you for help. Since Nightman suggested this before you but it didn't direct me to a solution, I will divide points between you 2. 2/3 to you and 1/3 to him
Thank you again both of you.
H
Yep, that worked. It was a big mistake on my part. Elements OtherLabourCosts, OtherMachineryCosts, ... OtherxxxxxxCosts are arrays!!! They didn't have array elements (0 lenght). I removed then from the stored procedure code. I will have to deal with them separately, maybe write them to a seperate table and associate them with the bm_overheads table
Thank you for help. Since Nightman suggested this before you but it didn't direct me to a solution, I will divide points between you 2. 2/3 to you and 1/3 to him
Thank you again both of you.
H
In that case what you can do is read the XML as varchar and convert the values in the select clause
For instance
FullTimeLabour Varchar(20) 'FullTimeLabour',
and in the select clause something like
convert(numeric(15,2),case when ISNUMERIC(FullTimeLabour)= 1 then FullTimeLabour else '0' end)
because FullTimeLabour is returned as empty string.
I know is a lot of writing, but it is a solution
For instance
FullTimeLabour Varchar(20) 'FullTimeLabour',
and in the select clause something like
convert(numeric(15,2),case
because FullTimeLabour is returned as empty string.
I know is a lot of writing, but it is a solution
ASKER
gpompe,
Maybe you didn't understand what I meant. All elements are numeric data except few that are named like OtherxxxCosts (where xxx = Labour or Machinery or Property etc). These elements represent an array in my C# code. When the array has values the XML portion that represents them looks like this
<OtherLabourCosts>
<OtherLabourCost">
<CostName> One</CostName>
<CostValue>0</CostValue>
<CostValueCC>0</CostValueC C>
<CostValueCCPercent>0</Cos tValueCCPe rcent>
</OtherLabourCost>
<OtherLabourCost">
<CostName> Two</CostName>
<CostValue>0</CostValue>
<CostValueCC>0</CostValueC C>
<CostValueCCPercent>0</Cos tValueCCPe rcent>
</OtherLabourCost>
</OtherLabourCosts>
<OtherPropertyCosts>
<OtherPropertyCost">
<CostName> House</CostName>
<CostValue>0</CostValue>
<CostValueCC>0</CostValueC C>
<CostValueCCPercent>0</Cos tValueCCPe rcent>
</OtherPropertyCost>
</OtherPropertyCosts>
They all have the same structure. The only way I can think of dealing with them is to write them all to one table which will have cost type (so I can tell if I am dealing with Labour costs or property costs etc) and ID that associates it with the parent row (bm_overheads) and the actual data columns. I think that should work. If you can think of an improvement/better soluton please let me know.
Thanks, your input is much appreciated
H
Maybe you didn't understand what I meant. All elements are numeric data except few that are named like OtherxxxCosts (where xxx = Labour or Machinery or Property etc). These elements represent an array in my C# code. When the array has values the XML portion that represents them looks like this
<OtherLabourCosts>
<OtherLabourCost">
<CostName> One</CostName>
<CostValue>0</CostValue>
<CostValueCC>0</CostValueC
<CostValueCCPercent>0</Cos
</OtherLabourCost>
<OtherLabourCost">
<CostName> Two</CostName>
<CostValue>0</CostValue>
<CostValueCC>0</CostValueC
<CostValueCCPercent>0</Cos
</OtherLabourCost>
</OtherLabourCosts>
<OtherPropertyCosts>
<OtherPropertyCost">
<CostName> House</CostName>
<CostValue>0</CostValue>
<CostValueCC>0</CostValueC
<CostValueCCPercent>0</Cos
</OtherPropertyCost>
</OtherPropertyCosts>
They all have the same structure. The only way I can think of dealing with them is to write them all to one table which will have cost type (so I can tell if I am dealing with Labour costs or property costs etc) and ID that associates it with the parent row (bm_overheads) and the actual data columns. I think that should work. If you can think of an improvement/better soluton please let me know.
Thanks, your input is much appreciated
H
I understand, but your problem is in SQL SERVER.
This the thing : When SQL SERVER reads the XML is trying to convert what it reads to Numeric(15,2) because you defined that.
So in this line, SQL SERVER reads an empty tag it fail to convert (implicit) it to numeric and that the error you get.
Now my approach is to overcome the problem with the implicit convertion is read the XML into varchar field (does not matter if there is a number or not).
So now you can read the XML, but the fields in your table (bm_overheads) are numeric. So you have to convert them.
If we try to convert them as is, it will fail again. To overcome this I am using the ISNUMERIC function (it receives a varchar and returns 1 if the value can be convert to a numeric value)
case when ISNUMERIC(FullTimeLabour)= 1 then FullTimeLabour else '0' end means if SQL can convert the value of the tag into numeric value, do it. Else the value is 0
The convert function is to explicitly convert the value, but you can omitt it and the values will be converted during the insert.
With this approach you do not have to modify the XML, just Insert query and final result is the same.
This the thing : When SQL SERVER reads the XML is trying to convert what it reads to Numeric(15,2) because you defined that.
So in this line, SQL SERVER reads an empty tag it fail to convert (implicit) it to numeric and that the error you get.
Now my approach is to overcome the problem with the implicit convertion is read the XML into varchar field (does not matter if there is a number or not).
So now you can read the XML, but the fields in your table (bm_overheads) are numeric. So you have to convert them.
If we try to convert them as is, it will fail again. To overcome this I am using the ISNUMERIC function (it receives a varchar and returns 1 if the value can be convert to a numeric value)
case when ISNUMERIC(FullTimeLabour)=
The convert function is to explicitly convert the value, but you can omitt it and the values will be converted during the insert.
With this approach you do not have to modify the XML, just Insert query and final result is the same.
ASKER
OK, I am with you. However, I removed these columns from the table as I cannot represent an array data in one column. I also removed them from the select in the stored procedure. This works fine now. It doesn't deal with these fields. I am the thinking of writing another insert into another table that holds these each array element in a row. will this work?
If I follow your suggestion, I believe the insert into bm_overheads will work ok. bm_overheads originally had 1 field for each array which was a mistake. It is not possible to insert the arrays into bm_overheads as I don't know how many array elements there will be at runtime. I will have to deal with the array data insert seperate from single item data insert into bm_overheads. I am not SQL savvy, so i maybe lost.
Cheers
H
If I follow your suggestion, I believe the insert into bm_overheads will work ok. bm_overheads originally had 1 field for each array which was a mistake. It is not possible to insert the arrays into bm_overheads as I don't know how many array elements there will be at runtime. I will have to deal with the array data insert seperate from single item data insert into bm_overheads. I am not SQL savvy, so i maybe lost.
Cheers
H