Solved

Writing SQL Query

Posted on 2007-04-05
3
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Database maintenance 36 107
compare date to getdate() 8 17
Help with Progress 4gl Rounding Function 6 26
Need to replicate a Log table 4 8
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

733 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