可能重複:
How to avoid the 「divide by zero」 error in SQL?如何避免被零錯誤劃分
我有一個關於Sql Server的零錯誤劃分的問題。 有時候這個錯誤和它被阻塞的視圖直到我刪除相應的行。 你能幫我,給我一些建議,我該如何避免這種情況? 謝謝。
CREATE VIEW Acq
AS
SELECT
ac_id
,[Company]
,No
,[ContractID]
,[Seller]
,[AcquistionDate]
,[Village]
,[Commune]
,[Area]
,[PlotArea]
,[FieldNo]
,[Topo1]
,[Topo2]
,[Topo3]
,[Topo4]
,[Topo5]
,[TotalAreaSqm]
,[OwnershipTitle]
,[CadastralNO]
,[Type]
,[Price]
,[NotaryCosts]
,[LandTax]
,[OtherTaxes]
,[AgentFee]
,[CadastralFee]
,[TabulationFee]
,[CertSarcini]
,[ProcuraNO]
,cast((isnull(price,0)+isnull(notarycosts,0)+isnull(landtax,0)+isnull(othertaxes,0)+isnull(agentfee,0)+isnull(cadastralfee,0)+isnull(tabulationfee,0)+isnull(certsarcini,0)) as decimal(12,4)) as TotalCosts
,cast((isnull(price,0)+isnull(notarycosts,0)+isnull(landtax,0)+isnull(othertaxes,0)+isnull(agentfee,0)+isnull(cadastralfee,0)+isnull(tabulationfee,0)+isnull(certsarcini,0))/(TotalAreaSqm/10000) as decimal(12,4)) as RonPerHa
,cast((isnull(price,0)+isnull(notarycosts,0)+isnull(landtax,0)+isnull(othertaxes,0)+isnull(agentfee,0)+isnull(cadastralfee,0)+isnull(tabulationfee,0)+isnull(certsarcini,0))/(TotalAreaSqm/10000*FixHist) as decimal(12,4)) as EurPerHa
,[DeclImpunere]
,[FixHist]
,cast((isnull(price,0)+isnull(notarycosts,0)+isnull(landtax,0)+isnull(othertaxes,0)+isnull(agentfee,0)+isnull(cadastralfee,0)+isnull(tabulationfee,0)+isnull(certsarcini,0))/FixHist as decimal(12,4)) as EurHist
,[LandStatus]
FROM tblAcq
非常感謝,它的工作! – user1820705