Pivot????
Code:
select ROWID,
[Col Code] as COLCODE,
[Range Code] as RANGECODE,
[Restriction Code] as RESTRICTIONCODE
from (select ROWID, ATTRIBUTENAME, VALUE from COLCODE
union all
select ROWID, ATTRIBUTENAME, VALUE from RANGECODE
union all
select ROWID, ATTRIBUTENAME, VALUE from RESTRICTIONCODE) pvt
pivot (max(VALUE) for ATTRIBUTENAME in ([Col Code], [Range Code], [Restrictive Code])) as ATTRIBUTEVALUE
I have three unions to pull some data, which gives me potentially three rows for each ID... I then pivot on the ID and select the MAX VALUE for each of the three items I want... the result of the union has three cols, the ID, which is a GUID, the ATTRIBUTENAME which is a text value "Col Code", "Range Code" or "Restriction Code" and the Value, which is also text. The pivot rotates the data so that Col Code, Them Range Code and Restriction Code become columns, the data is rotated on the ID, and the value in each col is the max value for that column by ID ... if that makes sense...
-tg