Currently within the program I am working on I have to compare tables in a database. To do this I intend to use an SQL outer
join. My problem is that I will have no idea how many tables I will have to select from or how many columns are to be retrieved.
I intend to create the SQL statment dynamically. Store it as a scalar and then run it. What I have left to do, which is causing me a little trouble, is the second half of the statement.
What may make it easier to understand if you are not a SQL person is what I need to do is create a string made up from values stored within arrays/hashes.
Below are a few examples of what I will have and what I need to create. The resulting code however has to work for any amount of arrays or values.
input:
%hash = ( "view0" => "buffersize, size, value",
"view1" => "buffersize, size, value");
output:
view0 full outer join view1 on view0.size = view1.size and view0.buffe
+rsize = view1.buffersize
please notice that the last value in each hash element is not included in the result
input:
%hash = ( "view0" => "buffersize, size, value",
"view1" => "buffersize, size, value",
"view2" => "buffersize, size, value");
output:
view0 full outer join view1 on view0.size = view1.size and view0.buffe
+rsize = view1.buffersize full outer join view2 on view1.size = view2.
+size and view1.buffersize = view2.buffersize
again the last element value in each hash element is omitted
input:
%hash = ( "view0" => "buffersize, size, value",
"view1" => "buffersize, size, value",
"view2" => "buffersize, size, value"
"view3" => "buffersize, size, value");
output:
view0 full outer join view1 on view0.size = view1.size and view0.buffe
+rsize = view1.buffersize full outer join view2 on view1.size = view2.
+size and view1.buffersize = view2.buffersize full outer join view3 on
+ view2.size = view3.size and view2.buffersize = view3.buffersize
Thanks. And if anything is unclear please ask. It does take a while to wrap your head around what is needed.
j
o
h
n
i
r
l
.
Sum day soon I'Il lern how 2 spelI (nad tYpe)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.