Click here to Skip to main content
15,895,142 members

Using Date Ranges in SQL Server 2005

BrianS1 asked:

Open original thread
I am having a problem with a query I am writing and would like to see if you guys could help out some? I have two integer fields with the same name in two different tables that I am trying to sum to get the total volume in a specified date range and my query is returning the worng results and I cannot figure out what is wrong. This is the query I am using:
(date is the primary key in both tables)
SQL
SELECT Sum(BOSS) AS TotalVolInRange
FROM Keyed_Data AS A INNER JOIN Stored_Vol_Counts AS B
ON A.Date = B.Date
WHERE A.Date >='2012-09-09' and <'2012-09-15' AND B.Date >= '2012-09-09' and <'2012-09-15'AND A.DisplayAsID = 35 AND B.DisplayAsID = 35;


I have also used this to no avail:
SQL
SELECT Sum(BOSS) AS TotalVolInRange
FROM Keyed_Data AS A INNER JOIN Stored_Vol_Counts AS B
ON A.Date = B.Date
WHERE A.Date between '2012-09-09' and '2012-09-15' AND B.Date between '2012-09-09' and '2012-09-15'AND A.DisplayAsID = 35 AND B.DisplayAsID = 35;


And this:
SQL
SELECT Sum(BOSS) AS TotalVolInRange
FROM Keyed_Data AS A INNER JOIN Stored_Vol_Counts AS B
ON A.Date = B.Date
WHERE A.Date between '09/09/12' and '09/15/12' AND B.Date between '09/09/12' and '09/15/12' AND A.DisplayAsID = 35 AND B.DisplayAsID = 35;



Any help would be greatly appreciated.This is the first time I have posted a question but use the site often as a reference :)

Thanks in advance,
BrianS.
Tags: SQL Server 2005, SQL Server, DateTime

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900