Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

"Join" Help Expand / Collapse
Posted Monday, December 16, 2013 11:46 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, December 18, 2013 11:45 PM
Points: 34, Visits: 193

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

ActivityID AckComments AckTime
1 acknowledged 07:30
10 acknowledged 10:02

ActivityID AckFixComment AckFixTime
2 on site to check 08:45
3 issue with part 09:30

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

102 ,issue with part ,09:30,issue resolved,10:13
103,NULL,NULL,changed bulb,12:09

Any help would be appreciated.

Post #1523538
Posted Tuesday, December 17, 2013 7:21 AM



Group: General Forum Members
Last Login: Tuesday, December 6, 2016 8:08 PM
Points: 16,145, Visits: 16,850
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 for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1523677
Posted Tuesday, December 17, 2013 10:44 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 12, 2016 6:51 AM
Points: 334, Visits: 215
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
Post #1523813
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse