January 14, 2005 at 8:18 am
I have a basic view that subtracts column A from column B and returns the difference in column C. But when I sum all columns and manually subtract B from A it doesn't equal the sum of column C.
Create VIEW v_MTSTM_ORDERPROFIT
select top 100 percent o.order_number,customer_charges - carrier_pay as Profit,customer_charges,carrier_pay,o.company,o.address1,o.address2,o.city,o.state,zip,o.corp_id,o.entered,r.pickupdateactual --,o.Account
from v_MTSTM_ORDERBYBILLTO o inner join v_mtstm_profitloss r on o.order_number = r.order_number
order by o.order_number
Then I run this to double check and subtact with a calculator Carrier_Pay from Customer_chrg but the Sum of Profit is about 2000 dollars off.
select sum(carrier_pay) as Carrier_Pay,sum(customer_charges)as Customer_Chrg,sum(profit) as profit from v_MTSTM_ORDERPROFIT
where pickupdateactual between '2004-01-01' and '2004-12-31 23:59:59.997'
Do I need to specfiy the scale or that the datatype is money?? Any thoughts would be appreciated thanks in advance!
January 14, 2005 at 8:31 am
What are the underlying data types look like?
And are there NULLs present?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
January 14, 2005 at 8:41 am
The view I pull off of v_MTSTM_ProfitLoss actually converts the table datatype of FLOAT to a SMALLMONEY (columns Carrier_Pay and Customer_Charges). There are no nulls at all.
January 14, 2005 at 9:32 pm
The problem is most likely that the datatype in one of the columns is FLOAT which using binary math instead of Decimal math with some very unexpected results. Recommend you change the FLOAT column to a DECIMAL column, permanently.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 19, 2005 at 8:21 am
Thanks Jeff I changed the column to a decimal in the table but I am still having the same problem. Should I format the Profit column that gets created in the query? Does it have a default data type if you don't specify one? The Profit column isn't in any of the views I reference it is created only in this paticular query sort of a virtual column I guess. Thanks again!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply