Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

query to return a date range.

Posted on 2011-03-01
4
Medium Priority
?
281 Views
Last Modified: 2012-05-11
I would like to use the query below to return a date range but its key is the LOUReturn field which determins which records in the date field. i'd also like to drop the hour/min/sec from the query. the code below parses ok but doesn't return any thing, but is i run it without the between date part all the data comes back. also I'll be building this query into SSRS report for weekly run.

use PCTSRS
select d.CM_ITEM_ID, d.CM_ITEM_NAME, d.CLIN, d.SEARCH_APPROVING_OFFICIAL as 'SAO', d.SEARCH_PROFESSIONAL as 'SP',
         r.FixedByPTO, r.DateReturned, r.LOUReturn, r.ErrorText
      from CLG_RETURNS r
            inner join CLG_DOCUMENTS d on r.ItemID = d.CM_ITEM_ID
      where r.LOUReturn = (1)and r.DateReturned between '2011-02-16 00:00:00.000' and '2010-03-10 00:00:00.000'
      
      order by r.DateReturned desc
0
Comment
Question by:richa1960
[X]
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
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Thomasian earned 2000 total points
ID: 35008455
>> r.DateReturned between '2011-02-16 00:00:00.000' and '2010-03-10 00:00:00.000'

That is because your "from" date is greater than you "to" date

Maybe you meant:

r.DateReturned between '2011-02-16 00:00:00.000' and '2011-03-10 00:00:00.000'
0
 
LVL 25

Expert Comment

by:reb73
ID: 35008471
Swap the datereturned values around, the lower value first and the higher value after..
0
 
LVL 10

Expert Comment

by:itcouple
ID: 35008635
Hi

Also make sure your date field doesn't contain time if it does than use DateDiff function for compare dates whcih usually is recommended for any date comparisons criterias.

Regards
Emil
0
 
LVL 25

Expert Comment

by:reb73
ID: 35008704
You could use a template like below (or even more preferable convert it to a parameterized stored procedure) -
use PCTSRS

declare @startdate datetime, @enddate datetime, @LOUReturn int

select	 @startdate = '2011-02-16'	-- Populate startdate her
	,@enddate = '2011-03-01'	-- populate enddate here
	,@LOUReturn = 1			-- Populate LouReturn value here

set @enddate = dateadd(second, -1, dateadd(day,1,@enddate))

select d.CM_ITEM_ID, d.CM_ITEM_NAME, d.CLIN, d.SEARCH_APPROVING_OFFICIAL as 'SAO', d.SEARCH_PROFESSIONAL as 'SP',
         r.FixedByPTO, r.DateReturned, r.LOUReturn, r.ErrorText 
from CLG_RETURNS r
            inner join CLG_DOCUMENTS d on r.ItemID = d.CM_ITEM_ID
where r.LOUReturn = @LOUReturn and r.DateReturned between @startdate and @enddate

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

610 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