Solved

SQL DATE filter on sales history

Posted on 2013-12-27
6
167 Views
Last Modified: 2014-01-03
I am trying to write a simple SQL query that sums a salesman sales by month, but the date seems to be my trouble.

What I need to see is summed sales by salesman for a particular month/year 11-2013


SELECT HDR.slspsn_no,SUM(LIN.sls_amt)
FROM oehdrhst_sql HDR
INNER JOIN oelinhst_sql LIN ON
HDR.inv_no=LIN.inv_no
WHERE HDR.inv_dt=(11-2013)
GROUP BY HDR.slspsn_no

As the above is written I get (0 row(s) affected)

Any help would be much appreciated
0
Comment
Question by:Jeremy Kirkbride
  • 3
  • 3
6 Comments
 
LVL 40

Expert Comment

by:Sharath
ID: 39742126
You need to extract only month/ year from the date field before applying the filter. What is your database?
0
 

Author Comment

by:Jeremy Kirkbride
ID: 39742278
SQL
0
 
LVL 40

Expert Comment

by:Sharath
ID: 39742324
SQL is not a database. I have asked if you are working in SQL Server/Oracle/DB2/MySQL or any other database?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Jeremy Kirkbride
ID: 39742465
SQL Server 2012, but I am writing a query with SQL Server Management Studio. That help?
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 39752240
try this.
SELECT HDR.slspsn_no, 
       SUM(LIN.sls_amt) 
  FROM oehdrhst_sql HDR 
       INNER JOIN oelinhst_sql LIN 
               ON HDR.inv_no = LIN.inv_no 
 WHERE RIGHT(CONVERT(VARCHAR(10), HDR.inv_dt, 103), 7) = '11/2013' 
 GROUP BY HDR.slspsn_no 

Open in new window

0
 

Author Closing Comment

by:Jeremy Kirkbride
ID: 39753607
Thanks so much, exactly what I needed. I'm sure simple for you, but I'm new to SQL
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now