ASP.NET - Not between sql query - Asked By saranya on 04-Dec-12 02:37 AM

Hi frndz!

Iam working in asp.net,C#. in my project i want sql query for:

when the user select from date and to date  and search it should show the person who are not logged in that date.

So i want sql query for this.I used not between but its giving wrong result. so give me the sql query its very urgent
Anurag replied to saranya on 04-Dec-12 04:52 AM
when the user select from date and to date  and search it should show the person who are not logged in that date.
Means?
Does it mean not logged in between From date and To date? If so your query seems ok.
This is also the same
Select Row1, Row2... FROM TableName where LoggedDateTime < @FromDate
UNION ALL
Select Row1, Row2... FROM TableName where LoggedDateTime > @ToDate
Here @FromDate and @ToDate are your variables
Chintan Vaghela replied to saranya on 06-Dec-12 02:03 AM
Hi there,

Make your query as following way
Declare @FromDate as DateTime
Declare @ToDatre as DateTime
 
Select * from TableName where LoginDate
 
not in
(
Select LoginDate from TableName
  where CONVERT(varchar(10),LoginDate,102) between
    CONVERT(varchar(10),@FromDate,102) AND CONVERT(varchar(10),@ToDatre,102)
)