Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
SQLGurl
Starting Member
2 Posts |
Posted - 2012-01-27 : 08:56:16
|
| Hi Everyone,I am running a query that works just fine however, I would like it to exclude value that are equal to zero.Basically my query looks at the commission that clients pay over a number of periods.So it goes like thisSELECTT.Client_Code as Client,SUM(CASE t.Transaction_Date WHEN DATEADD(day, DATEDIFF(day, 1, GETDATE()),0)THEN (ABS (t.transaction_commission) /((fx.Exchange_Bid + fx.Exchange_Ask)/2 )) ELSE 0 END)as Commission_DayFROM TABLE TJOINING FX TABLEWHEREfx.Currency = 'USD'and T.Salesman_Name in ('X''Y'Z)Group BYT.Client_CodeIt works perfectly fine however, we dont transact with our clients everyday so therefore this list will return all of our clients in the database and many will have generate zero commission. I want to keep the query along those lines I just need to insert something that says "ONLY SHOW WHEN Commission is not ZERO.Can you help? I've tried every way that I can think ofmany many thanks |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-01-27 : 09:02:25
|
Are you using SQL Server? The syntax doesn't seem like T-SQL. If you are using SQL server, add a having clause at the very end like this:...GROUP BY T.Client_CodeItHAVING SUM( CASE t.Transaction_Date WHEN DATEADD(DAY, DATEDIFF(DAY, 1, GETDATE()), 0) THEN ( ABS(t.transaction_commission) / ((fx.Exchange_Bid + fx.Exchange_Ask) / 2) ) ELSE 0 END ) <> 0 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-01-27 : 10:41:13
|
Couple of things...Your code is malformed..please post the actual code you have run (Is this SQL Server?)I cleaned it up some here, but the FROM Clause makes no sense SELECT T.Client_Code as Client , SUM(CASE t.Transaction_Date WHEN DATEADD(day, DATEDIFF(day, 1, GETDATE()),0) THEN (ABS (t.transaction_commission) /((fx.Exchange_Bid + fx.Exchange_Ask)/2 )) ELSE 0 END) AS Commission_Day FROM TABLE T JOIN FX TABLE ON ??????????? WHERE fx.Currency = 'USD' AND T.Salesman_Name in ('X','Y','Z')GROUP BY T.Client_CodeAlso, I'm guessing that you want to do this when Transaction Date is equal to today...Also, you might want to make sure that fx.Exchange_Bid + fx.Exchange_Ask is never 0, or you'll have a divide by zero errorAnd again...the FROM clauseFROM TABLE TJOINING FX TABLEWhat is that? Are you naming the FX Table alias TABLE?? KOINING?And you have no JOIN Predicate (ON)We need your actual Query, The table DDL would help, sample data in DML form and the expected resultsRead the hint link in my sigBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
|
|
|
|
|