satya128:
While you could write a perl script to do that, why not get your SQL tool to do it for you? That way you could use as few programs as possible.
First, you need to glue your queries together. I'm assuming they're currently something like this:
select XMOU
from Table1 where ...stuff...;
select YBLLD_MOU
from Table2 where ...morestuff...;
select ZCNT_CALL
from Table3 where ...otherstuffr...;
You can glue these queries together even though they have different selection criteria and use different tables. In addition, you can tell it to output the field name beside the value like this:
select 'XMOU' as the_name, XMOU as the_value
from Table1 where ...stuff...
union all
select 'YBLLD_MOU', YBLLD_MOU
from Table2 where ...morestuff...
union all
select 'ZCNT_CALL', ZCNT_CALL
from Table3 where ...otherstuffr...
The union word tells SQL that you want the results of the query below it to be appended to the same result set as the query before it. Two things of note: First, both queries need to return the same number of columns, and those columns need to have the same types in the same order. Second, you can name the columns of the output results with the 'as' word, as I did in the first query.
Once you've done that, then take a look at the manual for your SQL tool. Usually, there's an option to suppress column headers and row counts. If you set those, then you should be able to get the results you want without even involving perl.
Perl isn't always the answer--if you learn all your tools well, you can save yourself a lot of headaches. Of course, this all supposes that you're not wanting to do some additional processing in perl that you haven't mentioned. In that case, I'd either:
- Still use this trick (if it's a quick and dirty job), or
- Install DBI and the appropriate DBD module for your database, if you're going to be doing a lot of mixed perl and database work.
Update: Added 'ALL' per chacham's note.
...roboticus
When your only tool is a hammer, all problems look like your thumb. |