Solved

Writing SQL Query

Posted on 2007-04-05
3
333 Views
Last Modified: 2008-01-09
I am connecting to a historian and I can only connect to it with OLE DB and it only allows SET and SELECT statements in SQL queries. It follows the SQL-92 convention.

So I want to query one column in the historian and produce a few columns based on some kind of sorting.

In that one column in the historian the data looks like this:

BOAT_PART_A
CAR_PART_B
BOAT_PART_B
CAR_PART_A
PLANE_PART_B
PLANE_PART_A

I then want to sort that data into three columns looking like so:

column A| column B| column C
CAR_PART_A BOAT_PART_A PLANE_PART_A
CAR_PART_B BOAT_PART_B PLANE_PART_B
0
Comment
Question by:RizwanKhalid
  • 2
3 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 18862776
what is an historian ?
and i did not understand the format of your data
each row in
BOAT_PART_A
CAR_PART_B
BOAT_PART_B
CAR_PART_A
PLANE_PART_B
PLANE_PART_A

is one row (that is do you have 6 rows here) or is it only one row all togheter
0
 
LVL 3

Author Comment

by:RizwanKhalid
ID: 18863182
"historian" is the name of the table.

These are six rows in one column. You can assume that the table has only one column.
Basically what I want to do is convert this one column table into three column table in which the first column has all the data that starts with "BOAT_PART", second has "CAR_PART" and so on in the formate specified above.
There are following restriction:
1) Only SELECT and UPDATE statements are available
2) No temporary table can be used
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 18864742
ok
got you
in order to "create" 3 column from only one column you have to join the table  to itself twice, so the select that will create the table for you is
select
from historian t1, historian t2, historian t3
where t1.col like 'BOAT_CART%'
and  t2.col like 'CAR_PART%'
and t3.col like 'PLANE_PART%'
and right(t1.col,1) = right(t2.col,1)
and right(t2.col,1) = right(t3.col,1)

this will produce the table
you won't be able to update though, and i don't think you will be able to implement a solution that will allow an update
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes some very basic things about SQL Server filegroups.
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question