Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL DATE filter on sales history

Posted on 2013-12-27
6
171 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FizzBuzz challenge 9 82
Problem to page 4 93
Support for Notepad++ (including downloading & installing a plugin) 5 162
Problem to Alipay 10 44
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

829 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