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 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-02-03 : 07:40:29
|
| Hi,i have three tables. Element table,code table and Result table.Code table has 2 fields, codetid and code.codeid code1 a2 b3 c4 dResult table has elementid,value1 and value2 fields.elementid value1 value21 20 102 30 53 10 64 12 11 element table has elementname and codeid fieldscodeid elementname1 silver2 silver3 silver4 silver1 copper2 copper3 copper4 copper.. ...what i wanna do is to get a result set like below;elementname, value1 for a, value2 for a, value1 for b, value2 for b,value1 for c, value2 for c,value1 for d, value2 for d.silver , 20,10,30,5,10,6,12,11 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-03 : 19:08:47
|
[code]select e.elementname, [value1 for a] = max(case when c.code = 'a' then r.value1 end), [value2 for a] = max(case when c.code = 'a' then r.value2 end), [value1 for b] = max(case when c.code = 'b' then r.value1 end), [value2 for b] = max(case when c.code = 'b' then r.value2 end), . . .from element e inner join result r on e.codeid = r.elementid inner join code c on e.codeid = c.codeidgroup by e.elementname[/code] KH |
 |
|
|
|
|
|
|
|