May 2, 2004 at 8:31 pm
Hi friends
I've 2 tables Task and Assignments .task is PK table assignment is fk table
example data:
task table data
taskid,status,complete,buildver
416 80 1 6.57a
1024 70 1 6.64b
1124 60 1
this assignment table data
fk_staffid,fk_taskid,ass_startdate,ass_stopdate
NITIN 416 2003-05-01 00:00:00.000 NULL
CHRIS 1024 2003-11-10 00:00:00.000 NULL
rk 1124 2003-12-12 23:49:00.000 2003-12-15 13:25:00.000
how can i write query which returns data
Where task was completed > 4 months ago (there is field complete bit in task table if it .t. means task completed else not)
and assignment table assignment has assignment stop date(ass_stopdate)
Thanks
May 3, 2004 at 5:16 am
select taskid from task a
inner join assigment b on a.taskid=b.fk_taskid
where a.status = 1 and datediff(mm, b.ass_stopdate, getdate())>4
May 3, 2004 at 5:24 am
Haven't tested this but should work just fine. Notice how DATEADD was used to subtract 4 months from the current date... not a job for DATEDIFF as many would think...
--Jeff Moden
Change is inevitable... Change for the better is not.
May 3, 2004 at 6:08 am
"DATEADD(mm,-4,GETDATE())" would be preferable because that way, at.ass_stopdate will still be sargeble and it's index (?) might be used
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
May 4, 2004 at 2:48 pm
Thank u very much wz700 and Jeff for ur posts.
i finally decided to use Jeff's suggestion.
You guys r very helpful
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply