Sending SQL Queries output to different Excel sheets


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending SQL Queries output to different Excel sheets
# 1  
Old 05-28-2009
Sending SQL Queries output to different Excel sheets

Hi,

I need your help in sedning sql queries output to different excel sheets.

My requirement is like this:

Query1: Select name from table1 where status = 'Complete'
Query2: Select name from table1 where status = 'Failed'
Query3: Select name from table1 where status = 'Ignored'

When i execute these queries, i want output of Query1 to be on sheet1 and output of query2 to be on sheet2 and output of query3 on sheet3 of an excel file.

Not sure whether it can be achieved using sqlplus.

Could some one please help me in this.

Thanks .
Parvathi
# 2  
Old 05-28-2009
You can do that in perl using Simple::Excel
# 3  
Old 05-28-2009
Hi dinjo_jo,

Thanks for your inputs.
Could you please tell me the procedure to do that?
sorry for asking. I know perl but not to this extent.

Once again thanks.

Parvathi.
# 4  
Old 05-28-2009
I have being doing it in sybase using perl.

use Spreadsheet::WriteExcel;
use Spreadsheet::WriteExcel::Worksheet;
use Sybase:SmilieBlib;

my @results;


my $sql = "select *"
my $dbh = Sybase:SmilieBlib->new($user , $passwd , $server);
if (defined $dbh)
{
@results = $dbh->nsql($sql , "HASH");
}
else
{
print "No DB Connection found for $server";
}

my $ebook = Spreadsheet::WriteExcel->new(file);
my $esheet = $ebook->addworksheet($title);
my $format = $ebook->addformat();
my $formatheader = $ebook->addformat();
my $formatcolumn = $ebook->addformat();

$formatheader->set_size(20);
$formatheader->set_font('Verdana');
$formatheader->set_color('brown');
$formatheader->set_align('center');
$formatheader->set_bold();
$formatheader->set_merge();


$formatcolumn->set_size(10);
$formatcolumn->set_font('Verdana');
$formatcolumn->set_color('navy');
$formatcolumn->set_align('center');
$formatcolumn->set_bold();
$formatcolumn->set_italic();

$format->set_color('black');
$format->set_font('Verdana');
$format->set_align('center');

$esheet->write_blank(0,0,$formatheader);
$esheet->write_blank(0,1,$formatheader);
$esheet->write_blank(0,2,$formatheader);
$esheet->write_blank(0,3,$formatheader);
$esheet->set_column(0, 2, 25,$formatheader);


$esheet->set_column(2, 0, 25,$formatcolumn);
$esheet->set_column(2, 1, 25,$formatcolumn);
$esheet->set_column(2, 2, 25,$formatcolumn);
$esheet->set_column(2, 3, 25,$formatcolumn);
$esheet->set_column(2, 4, 25,$formatcolumn);


my $o = 0;
foreach my $values (@results)
{
$esheet->set_column(3,$o, 25,$format);
$esheet->write($i,0,"$values->{'Branches_ShortName'}",$format);
$esheet->write($i,1,"$values->{'Portfolios_ShortName'}",$format);
$esheet->write($i,2,"$values->{'Portfolios_Name'}",$format);
$esheet->write($i,3,"$values->{'Folders_ShortName'}",$format);
$esheet->write($i,4,"$values->{'Folders_Name'}",$format);
$i++;
$o++;
}

$ebook->close();
# 5  
Old 05-28-2009
Bug

Thanks dinjo_jo.

Will use this to get the results i am looking for.

Thanks alot...You have been very helpful.

Parvathi.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Help with storing the output of multiple sql queries to a file

Hi All, I have a file queries.txt as follows : SELECT COLUMN1 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN1 FROM SCDEMA2.TABLE2; SELECT COLUMN2 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN2 FROM SCDEMA2.TABLE2; SELECT COLUMN3 FROM SCHEMA2.TABLE1 MINUS SELECT COLUMN3 FROM SCDEMA2.TABLE2; SELECT... (2 Replies)
Discussion started by: SriRamKrish
2 Replies

4. Shell Programming and Scripting

Write two csv files into one excel with multiple sheets

I have requirement to write two CSV files to one single excel with multiple sheets. Data present in the two files should sit in excel as different sheets. How can we achieve this using shell script? 1.csv 2. csv 1,2,3,4 5,6,7,8 XXXXX YYYYY Res.excel 1.csv data... (1 Reply)
Discussion started by: duplicate
1 Replies

5. Shell Programming and Scripting

create separate files from one excel file with multiple sheets

Hi, I have one requirement, create separate files (".csv") from one excel file(xlsx) with multiple sheets. These ".csv" files are my source files. So anybody please suggest me the process. Thanks in Advance. Regards, Harris (3 Replies)
Discussion started by: harris
3 Replies

6. Shell Programming and Scripting

Help to get the Output of PL/SQL procedure In a Excel or Text File

Hi, Could anyone please guide me to get the output of the PL/SQL procedure in a Excel file or Text File... Thanks (1 Reply)
Discussion started by: funonnet
1 Replies

7. Shell Programming and Scripting

Run SQL queries in DB2 and output to file

Hi, I new to Unix and scripting. Following is my requirement. Can someone tell me whether its possible or not. Also please let me know how to proceed further if this is possible. List of queries are stored in a file. For example, I have to run a query like this: Select * from &XYZ where... (0 Replies)
Discussion started by: simhasuri
0 Replies

8. Shell Programming and Scripting

How to format excel sheets in UNIX??

Hi, I have generated an excel sheet using a shell script. i have converted the output text file to an excel and got the desired output. However, in a particular column in the excel the values of the numbers start with 0. e.g. 078393343, 00342442, etc. But, in the resulting excel I get as... (2 Replies)
Discussion started by: Vijay06
2 Replies

9. Shell Programming and Scripting

Multiple excel work sheets through UNIX

Hi, There is this requirement to create multiple work sheets in an MS Excel file through UNIX. We normally can create one work sheet in unix by either tab or comma delimiting and appending .xls or .csv to the file name, but can we create multiple work sheets. Regards, Puspendu (1 Reply)
Discussion started by: puspendu
1 Replies

10. Programming

creating more than 2 excel sheets in C

Hi, I have a question about using C to write excel file. There is a way to write into a sheet into a file excel, like this: FILE * File; pMyFile = fopen("test.xls", "w+"); fprintf(File, "\n\n"); /* go to the row 2 of the column A*/ fprintf(File, "%s", "Hi pippo!"); /* write... (7 Replies)
Discussion started by: manceryder
7 Replies
Login or Register to Ask a Question