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
 Transact-SQL (2005)
 Select Visitors Between Dates

Author  Topic 

mindtrap
Starting Member

10 Posts

Posted - 2010-05-25 : 07:33:02
I have developed visitor tracking program but have some problem with daterange select.


WHERE
(CAST(convert(varchar,startDate,112)as integer) <= CAST(convert (varchar,@EndDate,112)as integer) OR startDate IS NULL)
AND
(CAST(convert (varchar,startDate,112)as integer) >= CAST(convert (varchar,@StartDate,112)as integer) OR startDate IS NULL)


I want to select visitors which visit in between StartDate and EndDate what can I do?

All help will be apreciated and thank you in advance.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-05-25 : 07:47:32
What is the data type of startDate and @startDate?
Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-05-25 : 07:50:47
What is the datatype of startdate.

Incase it is datetime then you can use:
( startDate between @StartDate and @EndDate ) or (startDate IS NULL)


Incase it is varchar then you need to convert it to datetime.
(Convert(datetime,startDate,120) between @StartDate and @EndDate ) or (startDate IS NULL)

It will be better if you can post the script of table.
Go to Top of Page

mindtrap
Starting Member

10 Posts

Posted - 2010-05-25 : 08:52:51
Problem has been solved thanks for answers.
Go to Top of Page
   

- Advertisement -