Where StartDate >= '2013-01-01' and EndDate between '2013-01-01' and '2013-03-30'
Dear in AND condition both statement shold be true. According to ur table record first record match the and condition but second record match only first statement second statement is false thats why second record not fetch. I sujest u try OR condition.
NIELIT (DOEACC) "B" LEVEL
Software Engineer
A good programmer is someone who looks both side before crossing a one way street.
shahid.majee...
Member
620 Points
546 Posts
Select Query
Feb 24, 2013 02:36 PM|LINK
Hi I am trying to select some rows from my table and its not working what i wish to do Here is my table situation
ID StartDate EndDate
1 2013-01-01 2013-03-30
2 2013-01-01 2013-04-30
When i run my this select rows its just return first row i dont know why its not return second row
<div></div>Thanks in Advance
Shahid Majeed
Email: shahid.majeed@gmail.com
Anil Srivast...
Member
442 Points
292 Posts
Re: Select Query
Feb 24, 2013 02:46 PM|LINK
first criterion is only fulfilled(only one row returning)
no row is there
thanking you
Anil Sriivastava
shahid.majee...
Member
620 Points
546 Posts
Re: Select Query
Feb 24, 2013 02:52 PM|LINK
But i need to retrieve both rows . For example if a user want to select some rows between these dates start Date 2013-01-01 and ENDDate 2013-03-30
Shahid Majeed
Email: shahid.majeed@gmail.com
Ravi kant jh...
Participant
1180 Points
316 Posts
Re: Select Query
Feb 24, 2013 04:38 PM|LINK
Dear in AND condition both statement shold be true. According to ur table record first record match the and condition but second record match only first statement second statement is false thats why second record not fetch. I sujest u try OR condition.
Software Engineer
A good programmer is someone who looks both side before crossing a one way street.
imobsuz
Participant
1278 Points
195 Posts
Re: Select Query
Feb 24, 2013 10:45 PM|LINK
Hi,
I do not know if that's what you expect, but try:
Hope this helps.
oned_gk
All-Star
31377 Points
6414 Posts
Re: Select Query
Feb 25, 2013 12:40 AM|LINK
Your query working fine.
First query
Only one row match, the second row (2013-04-30) is not between 2013-01-01 -> 2013-03-30
The second query also same
oned_gk
All-Star
31377 Points
6414 Posts
Re: Select Query
Feb 25, 2013 12:52 AM|LINK
Use
Where ('2013-01-01' between StartDate and EndDate) or ('2013-03-30' between StartDate and EndDate)or one day selection
Where ('2013-01-01' between StartDate and EndDate)try also
The problem is you select range from two dates that i dont know what you want, all match or one match enaugh
Pbalan.in
Contributor
2142 Points
483 Posts
Re: Select Query
Feb 25, 2013 04:28 AM|LINK
Try this...
Declare @TempTable Table(RefNo numeric(18,0),Startdate datetime,Enddate datetime);
Insert into @TempTable Values (1,'1/1/2013','3/30/2013');
Insert into @TempTable Values (2,'1/1/2013','4/30/2013');
Select *
From @TempTable
Where StartDate >= '2013-01-01' or EndDate between '2013-01-01' and '2013-03-30'
Dont forget to mark as answer if it useful
prabu.raveen...
Contributor
5020 Points
955 Posts
Re: Select Query
Feb 25, 2013 05:31 AM|LINK
For your requirement, you have to check whether start date is in the period or enddate is in the period. Try as below,
Select *From KontorbokedRumWhere (StartDate between '2013-01-01' and '2013-03-14') or (EndDate between '2013-01-01' and '2013-03-14')
Harpreet09
Member
168 Points
41 Posts
Re: Select Query
Feb 25, 2013 09:11 AM|LINK
Try this
Regards
Harpreet Singh