Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select with a difficult record return query 1

Status
Not open for further replies.

Jamfool

IS-IT--Management
Apr 10, 2003
484
GB
My table basically consists of the following:>

ID,group_id,Description,Var1,Var2,Var3,Vartype


Basically I need a select statement that will gather all the records for a particular parent record via the group_id, which is pretty straightford in itself. Select * where group_id = parentId;

However each record in the child table consists of 3 var columns, which relate to the vartype column.

for example in one rowset>

var1 5
var2 10
var3 null
vartype numeric_min_max

Therefore I want output 5-10, Description

And in another rowset
var1 5
var2 5
var3 10
vartype %_m_s

I want this to be displayed as 5% per metre per second, Description.

Basically I need the select statement to take in to account the vartype, and use only the columns that it needs, and display them in a certain order.

Any help would be great :)
 
Some variant of case

Code:
select id,group,
case vartype
 when '%_m_s' then 
  var1 || '% per metre per second'
 when numeric_min_max then
   trim(var1) || '-' trim(var2)
 end, description
from t
 
Thanks, didnt know i could use a case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top