writing the output of SQL into one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting writing the output of SQL into one file
# 1  
Old 09-29-2009
writing the output of SQL into one file

Hi All,
Please help me writing the below script.

I have two sql queries.

1. Select count(1),Client_id from TABLE_A group by Client_id;
2. Select count(1),Client_id from TABLE_B group by Client_id;

I need the output of above two sql queries in a single file. The output 2nd query should be appended to the output of first query.

Thanks.
# 2  
Old 09-29-2009
Search the forums. You find several examples of how to do it.
# 3  
Old 09-29-2009
Alternatively, you can do that in the SQL script itself. Since you haven't mentioned what database you are using, I'd suggest you to check the SQL documentation of your database.

tyler_durden
# 4  
Old 09-30-2009
Quote:
Originally Posted by 46019
Hi All,
Please help me writing the below script.

I have two sql queries.

1. Select count(1),Client_id from TABLE_A group by Client_id;
2. Select count(1),Client_id from TABLE_B group by Client_id;

I need the output of above two sql queries in a single file. The output 2nd query should be appended to the output of first query.

Thanks.
Uh. What's wrong with these people - minimal information provided, maximum outcome required...

Given that this is an Oracle script, AND given that these queries are in different scripts:
  1. create a third script, say, thethirdscript.sql
  2. in that script, commands are
    1. spool thefileyouwanttocreate.log
    2. @scriptoneinyourmessage.sql
    3. @scripttwoinyourmessage.sql
    4. spool off
Or use similar method in yourveryowndatabasesoftware.

pen
# 5  
Old 09-30-2009
If your working on Unix/Linux you can use HERE Documents in a shell script, like this:

#!/bin/bash

( sqlclient user@password << EOF

Select count(1),Client_id from TABLE_A group by Client_id;
Select count(1),Client_id from TABLE_B group by Client_id;

disconn
EOF
) > query_op_file

If both the queries don't give desired output into the file, then get the output individually and then:

cat 2nd_query_op_file >> 1st_query_op_file (appends output of 2nd query to the first one)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wrong output when writing to file

Hello, I am having problem while redirecting output to a file where as on console output is proper. for dir in */; do printf "%s, " "$dir"; ls -m "$dir"; echo; done > output.txt Output of above command is coming in single line but when i am redirecting output to a file, single line i... (10 Replies)
Discussion started by: Manoj Rajput
10 Replies

2. Shell Programming and Scripting

Getting output with sed without writing to a file

HI I am trying to grep 3 characters from hostname and append a character at the end. I tried as in the following: root@abag3:~# hostname | cut -c1-3 hyu Now I am trying to append "g" at the end of this output as in the following. root@abag3:~# hostname | cut -c1-3 | sed -s... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

3. Shell Programming and Scripting

Writing output to a file in columns

Hi I am trying to write output to a file in columns I have file in the follwoing: # cat file abc def # I am trying to write next output as like # cat file abc 123 def 345 # :mad: (6 Replies)
Discussion started by: Priya Amaresh
6 Replies

4. Shell Programming and Scripting

Cat writing only one record in the output file

Hi All, I have an input file containing data as below: Input.DAT XXXXXXX|YYYYYYY|ZZZZZZZZZZ|12334446456|B|YY|111111111|111111111|111111111|111111111|15|3|NNNNNN|Y|3|AAA|111111111... (11 Replies)
Discussion started by: sagar.cumar
11 Replies

5. UNIX for Dummies Questions & Answers

Writing a script that will take the first line from each file and store it in an output file

Hi, I have 1000 files names data1.txt through data1000.txt inside a folder. I want to write a script that will take each first line from the files and write them as output into a new file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. Shell Programming and Scripting

To create a file writing a SQL into it from another file

Hi, I have a file in which I have database information along with 1 SELECT statement. Only 1 statement would be there. I want to grep this SELECT STATEMENT only and write into a separate file. Input File format: Database_Name:<database> Schema_Name:<schema> Table_Name:<table> Select *... (3 Replies)
Discussion started by: ustechie
3 Replies

8. Shell Programming and Scripting

Writing sql results to file using ksh -nevermind

I'm having problems with writing my sql results to a file: sqlplus -S username/password@DB <<!! set echo off set verify off set showmode off set feedback off set timing off set linesize 250 set wrap off set pagesize 0 set newpage none set tab off set trimspool on set colsep... (1 Reply)
Discussion started by: avillanueva
1 Replies

9. Shell Programming and Scripting

Writing output into different files while processing file using AWK

Hi, I am trying to do the following using AWK program. 1. Read the input data file 2. Parse the record and see if it contains errors 3. If the record contains errors, then write it into Reject file, else, write into usual output file or display it on the screen Here is what I have done -... (6 Replies)
Discussion started by: vidyak
6 Replies

10. Programming

Writing to a File using pl/sql

Hi I am new to using pl/sql on a unix platform and am having trouble writing to a file from within a block. Below is an example of the code that I have. I know that I need to use UTL_FILE to accomplish this; however, I keep getting errors. Can someone please help me? I am trying to create a... (1 Reply)
Discussion started by: stky13
1 Replies
Login or Register to Ask a Question