Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
pathania_garima
Starting Member
1 Post |
Posted - 2011-07-04 : 09:12:17
|
I have 4 tablesSample data and tables are belowSRticketid description ticketuid1012 abcd 45671013 efgh 56781014 sdfsdf 89011015 asdafg 3456WorkOrderwonum description origrecordclass origrecordid 12890 tryer SR 101212892 fdsfdsg SR 101312896 fdsfr SR 101212897 gghh WO 1267812900 fdsfr SR 1014Worklogworklogid recordkey description type1 1012 tkykyy initial2 1012 asaddewws update3 12890 mkkhj initial4 12890 lliu final5 1013 yyu final 6 1013 yppp initial7 12900 gskjdfk final Longdescriptionldkey ldownertable description4567 SR this is long description of SR 10125678 SR this is long description of SR 10138901 SR this is long description of SR 10143456 SR this is long description of SR 10151 Worklog here it is from worlog for recordkey 10122 Worklog more for recordkey 10123 Worklog here it is from worlog for recordkey 128904 Worklog more from worlog for recordkey 128905 Worklog here it is from worlog for recordkey 10136 Worklog more from worlog for recordkey 10137 Worklog here it is from worlog for recordkey 12900I need a query to display me the below result:ticketid wonum description worklogdetails1012 12890 abcd. this is long description of SR 1012 tkykyy. here it is from worklog for recordkey 1012. asaddewws. more for recordkey 1012. mkkhj.here it is from worlog for recordkey 12890.lliu.more from worlog for recordkey 12890 12896 1013 12892 efgh. this is long description of SR 1013 yyu. here it is from worklog for recordkey 1013. yppp. more from worlog for recordkey 1013 |
|
sonjan
Starting Member
22 Posts |
Posted - 2011-07-05 : 19:45:39
|
Try something like this:select distinct sr.ticketid, sr.description, workorder.wonum, workorder.description, worklog.*from sr with (nolock)left outer join workorder with (nolock) on workorder.origrecordclass = sr.origrecordclass and workorder.origrecordid = sr.origrecordidleft outer join worklog with (nolock) on worklog.siteid = sr.siteid where sr.siteid = ' 'and sr.ticketid = ' ' |
 |
|
|
|
|