September 23, 2009 at 1:43 pm
Table: TaskTable Current Date= 09/23/2009
Task DueDate
TaskA 09/21/2009
TaskB 09/23/2009
TaskC 09/25/2009
TaskD 09/24/2009
When i Select DueDate =09/23/2009 then i need to get TaskA and TaskB only
When i Select DueDate =09/25/2009 then i need to get TaskC Only
When i Select DueDate =09/24/2009 then i need to get TaskD Only
pls help me out
September 23, 2009 at 1:58 pm
kiran_ramisetti (9/23/2009)
Table: TaskTable Current Date= 09/23/2009Task DueDate
TaskA 09/21/2009
TaskB 09/23/2009
TaskC 09/25/2009
TaskD 09/24/2009
When i Select DueDate =09/23/2009 then i need to get TaskA and TaskB only
When i Select DueDate =09/25/2009 then i need to get TaskC Only
When i Select DueDate =09/24/2009 then i need to get TaskD Only
pls help me out
Please explain your output.
Why does Select DueDate = 09/23/2009 return TaskA and TaskB only?
Why does Select DueDate = 09/25/2009 return TaskC only?
Why does Select DueDate = 09/24/2009 return TaskD only?
September 23, 2009 at 2:04 pm
I made the assumption that you want any task that is due today or in the past.
create table #Task (Task varchar(10), Due smalldatetime)
insert #Task select 'TaskA','09/21/2009'
insert #Task select 'TaskB','09/23/2009'
insert #Task select 'TaskC','09/25/2009'
insert #Task select 'TaskD','09/24/2009'
if the date today is 9/23/2009 (any time after midnight)
then this query will work for you.
SELECT * FROM #TASK WHERE DUE < getdate()
Task Due
---------- ------------------------------------------------------
TaskA 2009-09-21 00:00:00
TaskB 2009-09-23 00:00:00
September 23, 2009 at 3:59 pm
Chuck Lucking (9/23/2009)
I made the assumption that you want any task that is due today or in the past.create table #Task (Task varchar(10), Due smalldatetime)
insert #Task select 'TaskA','09/21/2009'
insert #Task select 'TaskB','09/23/2009'
insert #Task select 'TaskC','09/25/2009'
insert #Task select 'TaskD','09/24/2009'
if the date today is 9/23/2009 (any time after midnight)
then this query will work for you.
SELECT * FROM #TASK WHERE DUE < getdate()
Task Due
---------- ------------------------------------------------------
TaskA 2009-09-21 00:00:00
TaskB 2009-09-23 00:00:00
Based on the original post, I don't think that is what is wanted. I'm waiting for the OP to explain the desired results as given in the original post.
September 24, 2009 at 3:35 am
that query need to written based on duedate,
current date =2009/09/23
but i have tasks on 21st, 22nd, 25th and 28th of 9th month and 2009
when i select current date(2009/09/23) then i need to get 21st, 22nd and 23rd taks,
when i select date(25th-09-2009) then i need to get only 25th task
when i select date(28th-09-2009) then i need to get only 28th task
only
September 29, 2009 at 5:42 am
The reply by grasshopper seems to be correct. You can make it general by passing the date you need.
Let variable @datepassed be the date for which you match the records
SELECT * FROM #task WHERE due< @datepassed
September 29, 2009 at 9:46 pm
kiran_ramisetti (9/24/2009)
that query need to written based on duedate,current date =2009/09/23
but i have tasks on 21st, 22nd, 25th and 28th of 9th month and 2009
when i select current date(2009/09/23) then i need to get 21st, 22nd and 23rd taks,
when i select date(25th-09-2009) then i need to get only 25th task
when i select date(28th-09-2009) then i need to get only 28th task
only
declare @passdate datetime
set @passdate = '2009-09-30'
/*Assume that getdate() is 2009-09-30*/
if (datediff(day,getdate(),@passdate)> 0)
begin
SELECT Task FROM TaskTable
WHERE DueDate = @passdate
end
else
begin
SELECT Task FROM TaskTable
WHERE DueDate <= @passdate
end
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply