Solved

Writing SQL Query

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…

746 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

11 Experts available now in Live!

Get 1:1 Help Now