SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Analysis Server and Reporting Services (2012)
 Help please
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

saragodia
Starting Member

United Kingdom
2 Posts

Posted - 08/23/2013 :  11:20:43  Show Profile  Reply with Quote
hi, sorry if it's too ametuere question but I am stuck with this for couple of days now. :(

I am trying to replicate mySQL query into SQL server. Within my SQL we used to use a field BBA which carried always 1 for each booking.

so the query in mySQL was
(SUM(IF(AdonProfit > 0,BBA,0))) AS No_ofAdons

however in SQL server we do not have a field BBA and therefore do not use SUM. Instead I use count distinct ConfNo (confirmations numbers) in order to count total adons sold.

So in SQL server I have written the query as

count(distinct (if(a.AdonProfit > 0,a.ConfNo,0))) as No_ofAdons

But it's not working for me. Any help would be much appropriated.

thanks

James K
Flowing Fount of Yak Knowledge

3565 Posts

Posted - 08/23/2013 :  11:42:45  Show Profile  Reply with Quote
Are you trying to get the number of entries for which AdonProfit is greater than zero, or sum up the add on profits? Assuming the former:
SUM(IIF(AdonProfit > 0, 1, 0))
Go to Top of Page

saragodia
Starting Member

United Kingdom
2 Posts

Posted - 08/23/2013 :  11:52:05  Show Profile  Reply with Quote
quote:
Originally posted by James K

Are you trying to get the number of entries for which AdonProfit is greater than zero, or sum up the add on profits? Assuming the former:
SUM(IIF(AdonProfit > 0, 1, 0))




I am trying to get the number of entries for which adProfit is greater than zero. Thanks
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3565 Posts

Posted - 08/23/2013 :  14:56:21  Show Profile  Reply with Quote
quote:
Originally posted by saragodia

quote:
Originally posted by James K

Are you trying to get the number of entries for which AdonProfit is greater than zero, or sum up the add on profits? Assuming the former:
SUM(IIF(AdonProfit > 0, 1, 0))




I am trying to get the number of entries for which adProfit is greater than zero. Thanks

Can you try the query I posted? That is exactly what it is meant to do.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000