I have some data in a table and I want to query it for data from it and depending upon when the query is is executed I want the query to take the current time stamp into consideration.
For example
declare @data table (id int, value nvarchar (50))
insert into @data values (1, 'First value')
insert into @data values (2, 'Second value')
insert into @data values (3, 'Third value')
insert into @data values (4, 'Fourth value')
Query 1
select * from @data
where value != 'First value'
and (value != 'Second value' and '2012-08-30 23:59:59' between '2012-08-30 23:59:59' and '2012-09-15 23:59:59')
Query 1 Returns ‘Third value’ and ‘Fourth value’
Query 2
select * from @data
where value != 'First value'
and (value != 'Second value' and '2012-08-29 23:59:59' between '2012-08-30 23:59:59' and '2012-09-15 23:59:59')
Query 2 don’t return any values, I want it to return
‘Second value’
‘Third value’
‘Fourth value’
All help is appreciated
Regards,
Jesper
Your second query will never return any values, as ‘2012-08-29 23:59:59’ is not between the other two dates.
It will certainly never return ‘Second Value’, as you specifically exclude it.
I think you need to be a bit clearer on the logic you are trying to implement, maybe replacing the last AND with an OR NOT will get you closer, but this is a guess.