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.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Inclusive @enddate

Author  Topic 

stevenc49
Starting Member

14 Posts

Posted - 2008-07-18 : 14:50:56
If you have @startdate and @enddate parameters, the @enddate is inclusive because it goes to 00:00:00.

For example, if I want data for the time period from January 1, 2008 to January 5, 2008 inclusive. The @startdate would be 1/1/08 and @enddate would be 1/6/08.

Can I make it so that the user will just need to enter 1/5/08?

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-18 : 14:52:27
concatenate the time '01/05/2008 23:59:59.99'
or try this

declare @enddate as datetime
set @enddate = '1/5/08'
select @enddate
set @enddate = @enddate + 1
select @enddate



"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

stevenc49
Starting Member

14 Posts

Posted - 2008-07-18 : 14:57:36
Sorry, I should've been more specific.

In my query, I got:
WHERE CREATED BETWEEN @startdate AND @enddate

I tried:
where CREATED BETWEEN @startdate AND '@enddate 23:59:59.99'
but it says it failed to convert from datetime to character string

Is there a correct way to do that?
Go to Top of Page

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-07-18 : 15:02:29
declare @startdate as datetime
declare @enddate as datetime

set @startdate = '1/1/08'
set @enddate = '1/5/08'

set @enddate = convert(varchar(10), @enddate, 101) + ' 23:59:59'
select @startdate, @enddate



"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-18 : 15:03:48
You should not convert to varchar, just stick with datetime.

CREATED >= @startdate AND CREATED < @enddate + 1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -