?
Solved

Writing SQL Query

Posted on 2007-04-05
3
Medium Priority
?
339 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

830 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