Need help on writing data to csv file
Hi,
I want to copy result of two diffrent sybase queries in adjacent cells of the csv file ,say query 1:select fund_id from table1 where fund_code=123 result1:ABC query 2:select end_date from table2 where fund_code=123 result2:31-Dec-2008 cell1 | cell2 ______ |_____ result1 | result2 _______ |________ I am using following command to send data to csv file. isql -Sserver -Ppassword -o result.csv Also please suggest how to append data to csv file for more queries. Thanks in advance..... |
Code:
select t1.fund_id || ',' || t2.end_date I think this is what you are asking for. |
Probably
Code:
man join |
Thanks crabboy for your quick reply...yaa..I think this query will work....But I had given just sample queries.
My actual queries are: 1)select min(start_time) from table1 where req_name='s_20080709' and end_date='6/30/2008' 2)select max(upd_time) from table1 where req_name='s_20080709' and end_date='6/30/2008' 3)select min(start_time) from table1 where req_name='s_20080709' and end_date='7/31/2008' 4)select max(upd_time) from table1 where req_name='s_20080709’ and end_date='7/31/2008' As you can see table name is same for all the queries but end_date is different for first two and last two queries. I can combine query1 and query2 to single query and pass result to csv file and can combine query3 and query4 to single query and pass result to csv file. How can I handle the field end_date,so that I can combine the result of all four queries and pass it to csv file.so that it will look like in csv file as below. server1: result1 |result2| result3| result4| Please help on how to append data to csv file as I will be running these quries for different servers. server1: result1 |result2| result3| result4| server2: result1 |result2| result3| result4| |
You did not specify what database you are using, but for Oracle, something like this will work:
Code:
create or replace procedure test1( condition1 varchar2, condition2 varchar2, condition3 varchar2) as Code:
SQL> execute test1( 's_20080709’, '6/30/2008', '7/31/2008' ); test.sql Code:
set serveroutput on; Code:
OUTFILE=test.out |
Thanks a lot crabboy......:) I am using Sybase as database as I used command "isql -Sserver -Ppassword -o result.csv" in my first post...As per your reply,got an idea how to proceed further...I will try to use that for Sybase.
|
Hi crabboy.....could you please post the solution for Sybase as well in detail as you provided for the oracle like creating procedure,running it,passing parameters to it etc.as I tried to work on that but getting some errors with Sybase procedure....
|
How to copy result of exec command in sybase to csv or data file
Hi,
I am executing Sybase procedure test3 create procedure test3( @condition1 varchar(20), @condition2 varchar(20), @condition3 varchar(20) ) as DECLARE @lv_min varchar(20), @lv_max varchar(20), @lv_min2 varchar(20), @lv_max2 varchar(20) begin select @lv_min=(select min(start_time) from tabel1 where requestor_name= @condition1 and end_date= @condition2) select @lv_max=(select max(upd_time) from tabel1 where requestor_name= @condition1 and end_date= @condition2) select @lv_min2=(select min(start_time) from tabel1 where requestor_name= @condition1 and end_date= @condition3) select @lv_max2=(select max(upd_time) from tabel1 where requestor_name= @condition1 and end_date= @condition3) select @lv_min select @lv_max select @lv_min2 select @lv_max2 end >exec test3 's_20080709’, '6/30/2008', '7/31/2008' and the results are ------ result1 ------- result2 ------- result3 ------- result4 How to copy these results to csv file,so that it will look like.. cell1 cell2 cell3 cell4 result1|result2|result3|result4 |
copying data from a text file to csv file
Hi,
Can someone help me in copying data from a text file to csv file using shell script. Say my text file is hi.txt with following contents: monday tuesday wedneday I can use: cat hi.txt > queue.csv but the output is not copied properly to csv file. it should look like: cell1 | cell2 | cell3 monday | tuesday | wedneday i.e.first text from text file should go in first cell of csv file,second text in second cell and so on... Thanks in advance....... |
Please do not start multiple threads on the same subject. I'm merging the two recent ones into your original thread.
|
Hi,
Can any one tell me how to copy data to a excel/csv file from text file to other columns,leaving first column unaffected i.e it should not overwrite data in first column using shell script. Say my text file data is: 15-dec-2008 15-dec-2009 16-dec-2008 16-dec-2009 say my first excel column is: column1 column2 column3 server1 server2 I want output as below: column1 column2 column3 server1 15-dec-2008 15-dec-2009 server2 16-dec-2008 16-dec-2009 Thanks in advance........ |
Hi,
Try this : 1- place the server list in a file (f1.txt) 2- convert the excel file into a space separated file (say f2.txt) Then type Code:
paste f1.txt f2.txt > resutl.txt To get a cvs file, type Code:
paste f1.txt f2.txt | sed 's/[\t| ]/;/g' > resutl.cvs Hope it helps. |
hey thanks buddy...it helped me a lot.....:)
|
All times are GMT -5. The time now is 06:17 PM. |