December 16, 2013 at 11:46 pm
Hi
Hope that the forum members are doing fine.I would require some help with probably what I feel is "Join". The scenario is as per below
1. Activity table -which has eventid,activityID and statuscode.
2. ActivtyAck table - which has activityid, ackcomments
3. Acitivtyfixed - which has activityid,fixcomments,fixtime
4.Activitycomplete - which has activityid,completecomments,completetime
Once the event is acknowledged it creates an activityid,Each time an event is being fixed it creates activityid, similarly each time an event is being complete it creates an activityid and the comments for each of the fixes and completed are captured in their respective tables.
For eg. Event 102 initially when acknowledged say it creates an activityid 1,when fixing it creates activityid 2 and when completing it creates 3. All the basic information will be held in activity table as shown below
Activity Table
Event ActivityID StatusCode
102 1 D
102 2 F
102 3 F
102 4 C
103 10 D
103 11 C
ActivityAck
ActivityID AckComments AckTime
1 acknowledged 07:30
10 acknowledged 10:02
ActivityFix
ActivityID AckFixComment AckFixTime
2 on site to check 08:45
3 issue with part 09:30
ActivityComplete
ActivityID AckCompleteComment AckCompleteTime
3 issue resolved 10:13
11 changed bulb 12:09
I would like to know whether i could get a report as
EventID,AckFixComment,AckFixtime,AckCompleteComment,AckCompleteTime
102 ,issue with part ,09:30,issue resolved,10:13
103,NULL,NULL,changed bulb,12:09
Any help would be appreciated.
Thanks
Liju
December 17, 2013 at 7:21 am
Yes it sounds like you need to join your tables together. What have you tried so far?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
December 17, 2013 at 10:44 am
Just a piece of advice: Always its a good practice if you can post the code for creating objects and data. That way, it will be easy for every one as we all do not have to create the objects and the data you are referring to.
Try this:
Select A.eventid, B.ackcomments,C.fixtime,D.completecomments, D.completetime
From Activity A
JOIN ActivtyAck B
ON A.activityID = B.activityID
JOIN Acitivtyfixed C
ON A.activityID= C.activityID
JOIN Activitycomplete D
ON A.activityID= D.activityID
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply