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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

coverting rows to columns

Status
Not open for further replies.

bj1

MIS
Nov 11, 2002
53
AU
How would i go about converting this:

37 2003-12-13 00:56:43.000 -199.0
38 2003-12-13 00:56:43.000 -9.0
37 2003-12-13 00:56:44.000 117.0

to this:

xddatetime tilt54 pitch55

2003-12-13 00:56:43.000 -199.0 -9.0
2003-12-13 00:56:44.000 117.0

where tilt54 is sensorid 37 and pitch55 is sensorid 38.

is this possible?

i am currently using this query:

select xdsensorid, xddatetime, xdvalue, xdlongitude, xdlatitude
from his_externaldata o
where abs(xdvalue) =
(select max(abs(xdvalue))
from ((vmi_vehicles
inner join ext_sensors on vunitid = sunitid)
inner join his_externaldata on xdsensorid = ssensorid)
where vdescription = 'Shell 153456'
and (schannelnumber = 54 or schannelnumber = 55)
AND xdsensorid = o.xdsensorid
AND xddatetime = o.xddatetime)
order by xddatetime, xdsensorid;

any help is much appreciated.
B
 
you can use a Sub Query in your SELECT Clause.

I'm assuming tilt is sensor 37 and pitch is 38 so it would be

I'm assuming the table name is sensordata
The columns are

sensor
xddatetime
value


Code:
SELECT t.xddatetime, t.value as Tilt , p.value as Pitch
  FROM sensordata t
  LEFT OUTER JOIN sensordata p
    ON t.xddatetime = p.xddatetime
   AND p.sensor = 38
 WHERE t.sensor = 37
 
sorry for my ignorance, but i'm not sure i understand where this sub query fits into the query i already have...

can you provide more assistance?

thank you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top