Author |
Topic |
dheritage
Starting Member
3 Posts |
Posted - 2011-03-21 : 12:57:24
|
I've inherited a database where data I would like to display as two columns actually exists in two rows and a related field in another table. (It is a ticketing system).Table ATicID, FieldID, IntValTable BFieldID,listOrder,LabelWhat happens is for every TicID there are three fieldIDs (1,2,3) and thus three IntVals that go along with that. No problem until I want a view that shows a ticid, and the label from Table_B that corresponds to the fieldid/intval for fieldids 2 and 3. I get two rows back, each with the correct data per se, but since the unique 'pair' of data created by combining filedid and intval is what I want.... I cannot see how to get there. Here is the line as I have it so far, but I'd like help on getting this as a single row with two columns and not two rows (if that even makes sense).select a.ticid, a.fieldid, a.intval, b.label from a left join b on a.intval=b.listorder and a.fieldid=b.fieldid where a.fieldid in (2,3) |
|
X002548
Not Just a Number
15586 Posts |
|
dheritage
Starting Member
3 Posts |
Posted - 2011-03-21 : 16:03:33
|
Here is some sample data.Table ATicID, FieldID, IntVal26861,2,226861,3,428456,2,728456,3,231978,2,131978,3,333903,2,133903,3,434702,2,134702,3,3Table BFieldID,listOrder,Label2,1,open2,2,on hold2,3,closed2,5,scheduled2,4,to schedule2,5,scheduled2,6,call2,7,waiting on response2,8,waiting on permission2,9,waiting on delivery2,10,pending closed3,1,critical3,2,high3,3asap3,4,normal3,5,lowHuman readable, ticket # 26861 has status of on hold and priority of normalI would like to return only one row for each ticket #, with a column for status and another for priority. |
 |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-03-22 : 14:54:31
|
Check if this is what you are looking for Select A.TicID,Max(Case when A.FieldID=2 then B.Label end) as [Status],Max(Case when A.FieldID=3 then B.Label end) as [Priority]from @tableA AInner Join @tableB B on A.FieldID=B.FieldID and A.IntVal=B.listOrderGroup by A.TicIDCheersMIK |
 |
|
dheritage
Starting Member
3 Posts |
Posted - 2011-03-22 : 15:33:26
|
Fabulous! Just Fabulous! Thank you so very much. |
 |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-03-22 : 15:45:01
|
you are welcome CheersMIK |
 |
|
|
|
|