Solved

Writing SQL Query

Posted on 2007-04-05
3
332 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Read about achieving the basic levels of HRIS security in the workplace.
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now