Sum of 'Bit' = true or 1

In access the sql statement works fine, however i reciently changed these tables to MSSQL and it will not work.

SELECT Sum([CashSaleyn]=1) AS totalincome
FROM financelog;

Message is incorrect syntex or somthing

The cashsaleyn is set as a bit, should i change it? (in access it was a yn)
or is there another way
kleighAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NeoTeqCommented:
I'd say the easiest way to get the results wanted (the number of records where [CashSaleyn] is true) is the following query:

SELECT COUNT(*) AS totalincome
FROM financelog
WHERE CashSaleyn = -1;
kleighAuthor Commented:
bigger picture....

SELECT FI1_FinanceManagers.FirstName & ' ' & FI1_FinanceManagers.LastName AS RealName, FI1_FinanceManagers.userid, Sum(FI1_financelog.financereserve+FI1_financelog.lifeRes+FI1_financelog.disres+FI1_financelog.espres+FI1_financelog.easyres+FI1_financelog.maintres+FI1_financelog.rcres+FI1_financelog.wcres+FI1_financelog.etchres)/(sum(FI1_financelog.cashsale=false)*-1) AS totalincome, Sum(FI1_financelog.cashsale=False)*-1 AS dealcount
FROM FI1_FinanceManagers INNER JOIN FI1_financelog ON FI1_FinanceManagers.FinanceManagerID = FI1_financelog.FinanceManagerID
WHERE #PreserveSingleQuotes(Criteria)#
GROUP BY FI1_FinanceManagers.FirstName & ' ' & FI1_FinanceManagers.LastName, userid
HAVING ((Sum(FI1_financelog.cashsale=False) * -1 > #musthave#))
ORDER BY Sum(FI1_financelog.financereserve+FI1_financelog.lifeRes+FI1_financelog.disres+FI1_financelog.espres+FI1_financelog.easyres+FI1_financelog.maintres+FI1_financelog.rcres+FI1_financelog.wcres+FI1_financelog.etchres)/Count(FI1_financelog.dealno) DESC;

As you can see i need the sum of these bit fields as a count of 1's or 0's

Guy Hengel [angelIII / a3]Billing EngineerCommented:
SELECT Sum( case when ([CashSaleyn]=1 then 1 else 0 end ) AS totalincome
FROM financelog;
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

kleighAuthor Commented:
here it is with data:

  SELECT FI1_FinanceManagers.FirstName & ' ' & FI1_FinanceManagers.LastName AS RealName, FI1_FinanceManagers.userid, Sum(FI1_financelog.financereserve+FI1_financelog.lifeRes+FI1_financelog.disres+FI1_financelog.espres+FI1_financelog.easyres+FI1_financelog.maintres+FI1_financelog.rcres+FI1_financelog.wcres+FI1_financelog.etchres)/(sum(FI1_financelog.cashsale=false)*-1) AS totalincome, Sum(FI1_financelog.cashsale=False)*-1 AS dealcount FROM FI1_FinanceManagers INNER JOIN FI1_financelog ON FI1_FinanceManagers.FinanceManagerID = FI1_financelog.FinanceManagerID WHERE (((FI1_FinanceLog.DelDate) >= {d '2005-01-01'} AND (FI1_FinanceLog.DelDate) <= {d '2005-12-31'}) AND ((FI1_FinanceManagers.Active)=True)) GROUP BY FI1_FinanceManagers.FirstName & ' ' & FI1_FinanceManagers.LastName, userid HAVING ((Sum(FI1_financelog.cashsale=False) * -1 > 105)) ORDER BY Sum(FI1_financelog.financereserve+FI1_financelog.lifeRes+FI1_financelog.disres+FI1_financelog.espres+FI1_financelog.easyres+FI1_financelog.maintres+FI1_financelog.rcres+FI1_financelog.wcres+FI1_financelog.etchres)/Count(FI1_financelog.dealno) DESC;
NeoTeqCommented:
In that case, angelIII is correct.
kleighAuthor Commented:
this is the message i get when i try that

Incorrect syntax near the keyword 'then'.
NeoTeqCommented:
try:

sum(case [CashSaleyn] when 1 then 1 else 0 end)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kleighAuthor Commented:
that seems to be ok when counting 1's
What if i want a count of 0

NeoTeqCommented:
Just the other way around:

sum(case [CashSaleyn] when 1 then 0 else 1 end)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.