Query output in Excel
Hi ,
I have a job with number of queries. I need that output of the query in an excel format to a location whenever that job runs. Help me out.
>> and there was little explanation behind it <<
There is no need for further explanations. Each component in a system has its own responsabilities.
You should use the right tool for the right job. Calling console apps is not the responsability of the database engine and there are better ways to do that job.
>>
Personally I've found that if you can't integrate a C# library through CLR then using the console is a perfectly legitimate way of getting around that issue.
<<
I would like to know what feature you needed to implement that required xp_cmdshell.
But in this case, getting several queries exported to excel files in a job can be done by invoking the console app from the SQL Server Agent Job. No need for xp_cmdshell at all.
In our organization, we create lots of LOB web applications. Most of them have the option to export the data coming form SQL Server queries shown on grids to Excel files. Guess what? We don't call xp_cmdshell.
Jesús López
EntityLite: A Lightweight, Database First, Micro ORM
Similar Messages
-
How to get the Query output to Excel
Hi ,
Can you tell me how to get the Query output to excel with out using any third party tool?
Can you tell me how to write the code in Webservice and call it..
Please explain it Elaboartly..
Thanks in Advance!!!
Miniwhats your source system?
you can use Live office, or query as a webservice if you are getting data from universe
if you're getting data from SAP BI query and you have a java stack on your netweaver then you can get the data directly using sap bi connector in xcelsius.
good luck -
Hi,
How do I redirect the output of the SQL query to EXCEL format.
If i say select * from emp with the spooling file name as c:\emp.xls and once I open emp.xls the excel file should be available
with each column of the table in separate column automatically.
Please help me to achieve this requirement.
ThanksHi
Please find below script...Longback blushadow provided to me...!! Credit goes to his account only.
Thanks blushadow once again.
** This will help you a lot. do the following steps with out fail.
Now open tab.xls with excel ....
As sys user:
CREATE OR REPLACE DIRECTORY TEST_DIR AS 'c:\myfiles' /* directory on the Oracle database server */
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
As myuser:
DECLARE
v_fh UTL_FILE.FILE_TYPE;
v_dir VARCHAR2(30) := 'TEST_DIR';
v_file VARCHAR2(30) := 'myfile.xls';
PROCEDURE run_query(p_sql IN VARCHAR2) IS
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
BEGIN
c := DBMS_SQL.OPEN_CURSOR;
-- parse the SQL statement
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
-- start execution of the SQL statement
d := DBMS_SQL.EXECUTE(c);
-- get a description of the returned columns
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
-- bind variables to columns
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,4000);
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,4000);
END CASE;
END LOOP;
-- Output the column headers
UTL_FILE.PUT_LINE(v_fh,'<ss:Row>');
FOR j in 1..col_cnt
LOOP
UTL_FILE.PUT_LINE(v_fh,'<ss:Cell>');
UTL_FILE.PUT_LINE(v_fh,'<ss:Data ss:Type="String">'||rec_tab(j).col_name||'</ss:Data>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Cell>');
END LOOP;
UTL_FILE.PUT_LINE(v_fh,'</ss:Row>');
-- Output the data
LOOP
v_ret := DBMS_SQL.FETCH_ROWS(c);
EXIT WHEN v_ret = 0;
UTL_FILE.PUT_LINE(v_fh,'<ss:Row>');
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
UTL_FILE.PUT_LINE(v_fh,'<ss:Cell>');
UTL_FILE.PUT_LINE(v_fh,'<ss:Data ss:Type="String">'||v_v_val||'</ss:Data>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Cell>');
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
UTL_FILE.PUT_LINE(v_fh,'<ss:Cell>');
UTL_FILE.PUT_LINE(v_fh,'<ss:Data ss:Type="Number">'||to_char(v_n_val)||'</ss:Data>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Cell>');
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
UTL_FILE.PUT_LINE(v_fh,'<ss:Cell ss:StyleID="OracleDate">');
UTL_FILE.PUT_LINE(v_fh,'<ss:Data ss:Type="DateTime">'||to_char(v_d_val,'YYYY-MM-DD"T"HH24:MI:SS')||'</ss:Data>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Cell>');
ELSE
DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
UTL_FILE.PUT_LINE(v_fh,'<ss:Cell>');
UTL_FILE.PUT_LINE(v_fh,'<ss:Data ss:Type="String">'||v_v_val||'</ss:Data>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Cell>');
END CASE;
END LOOP;
UTL_FILE.PUT_LINE(v_fh,'</ss:Row>');
END LOOP;
DBMS_SQL.CLOSE_CURSOR(c);
END;
PROCEDURE start_workbook IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'<?xml version="1.0"?>');
UTL_FILE.PUT_LINE(v_fh,'<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">');
END;
PROCEDURE end_workbook IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'</ss:Workbook>');
END;
PROCEDURE start_worksheet(p_sheetname IN VARCHAR2) IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'<ss:Worksheet ss:Name="'||p_sheetname||'">');
UTL_FILE.PUT_LINE(v_fh,'<ss:Table>');
END;
PROCEDURE end_worksheet IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'</ss:Table>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Worksheet>');
END;
PROCEDURE set_date_style IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'<ss:Styles>');
UTL_FILE.PUT_LINE(v_fh,'<ss:Style ss:ID="OracleDate">');
UTL_FILE.PUT_LINE(v_fh,'<ss:NumberFormat ss:Format="dd/mm/yyyy\ hh:mm:ss"/>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Style>');
UTL_FILE.PUT_LINE(v_fh,'</ss:Styles>');
END;
BEGIN
v_fh := UTL_FILE.FOPEN(upper(v_dir),v_file,'w',32767);
start_workbook;
set_date_style;
start_worksheet('EMP');
run_query('select * from emp');
end_worksheet;
start_worksheet('DEPT');
run_query('select * from dept');
end_worksheet;
end_workbook;
UTL_FILE.FCLOSE(v_fh);
END;KPR -
WebGui: Download Query-output to excel
Hi everyone,
We are using ITS 6.20 patch-level 10 (level 16 will follow this week) in combination with R/3 4.70 Ext. 1.0 and we experience some system behavior that is not really user-friendly.
When calling a query (tx sq01) within WEBGui you've got the possibility to get the output as an ALV-List. Within the list you've got a button to download it to a local file as a spreadsheet. But when doing so the user has to confirm several screens for 'technical reasons'.
Does anyone know a way (or a workaround) to avoid this 'technical screens'?
Moreover the downloaded file should be a real XLS-File but it is a tab-separated text-file. Does anyone know how to get the same XLS-ready file within WEBGUI as you can get it in SAPGUI?
Thank you for your help.
Regards,
VinzenzHi Vinzenz,
I regret that the SAP GUI for HTML is not capable of exporting a XLS-file.
Best regards,
Henning. -
Query output to excel sheet...pls solve my problem here !
Hi all,
I have written a procedure which accepts parameters and generate a web page.
The web page generated records as fetched from cursor within procedure.
My requirement is to generate it as a excel sheet once run through url.
I am getting as a text inspite using
owa_util.mime_header('ms-excel');
within my code.....
can you pls help or send me code which could do above task...:)
Thanks in advance.
Regards
RavikanthTry this instead :
OWA_UTIL.MIME_HEADER('application/vnd.ms-excel');
Barry C
http://www.myoracleportal.com -
SAP Query output download to Excel
Hi All,
Once I export/download Query Output to Excel the fields are not in the order of Actul Query output
<u><i><b>Char fields are treated as Key fields and displayed Left side.</b></i></u>
As it is a SAP Query where to keep this kind of setting(key columns = 0).?
Thanks in advance and useful answer will be awarded.
cheers!!
Komatsuwhen u download data to excel sheet, u can't handle the data from SAP....The data in excel takes excel properties and accordingly data gets adjusted to the formats of excel.
If u need formatting u need to use OLE concepts in SAP from which u can set the formats of Excel Sheet. -
SAP Query output download to excel fields order is different
Hi All,
while download Query Output to Excel the fields are not in the order of actual Query output
Char fields are treated as Key fields and displayed Left side.
As it is a SAP Query where to keep this kind of setting(key columns = 0).?
Thanks
Komatsuwhen u download data to excel sheet, u can't handle the data from SAP....The data in excel takes excel properties and accordingly data gets adjusted to the formats of excel.
If u need formatting u need to use OLE concepts in SAP from which u can set the formats of Excel Sheet. -
HI All,
I need the sql query output in Excel sheet.
We use sqlunload for this.
But my requirement is to export
2 sql query in 2 tabs of a single excel sheet.
Please let m eknow how to process this.
Thanks,
LonyAny idea how to work on this one?
-
Please Vote if you find this to be helpful!
App-V PowerShell: Script to Query XenApp Servers for App-V Publishing Errors and Output an Excel Document with the Results
Just posted this to the wiki:
http://social.technet.microsoft.com/wiki/contents/articles/25323.app-v-powershell-script-to-query-xenapp-servers-for-app-v-publishing-errors-and-output-an-excel-document-with-the-results.aspxHi petro_jemes,
Just a little claritification, you need to add the value to the variable "[string]$ou", and also change the language in the variable "$emailbody" in the function "Get-ADUserPasswordExpirationDate".
I hope this helps. -
Query output transfer to excel file
hi all,
how can i query output transfer to excel file ? i am not using any tool. please suggest me. is there any method that i transfer that output to excel file?You can create a csv file. See dump_csv function from Tom Kyte.
-
Issue with Saving the Query output data in Excel format
Hi,
Recnetly we had upgraded from 4.6c to ECC 6.0.
In ECc 6.0 environment, when user try to export the query output , we are getting only XML option to save the data.
But user want to save the data in EXcel format, he was able to do that in 4.6C.
pleas eprovide some inputs, on this issue.
Thanks,
Sanketh.I cannot for the life of me imagine, why a link to a post in the 'Business One Forum' where one uses ODBC to transfer query-data to MicroSoft Excel is of relevance to the OPs question, even if the same is not a security issue.
Never mind. [note 40155|https://service.sap.com/sap/support/notes/402155] deals with various symptoms in the ALV-Excel combination as as of release 4.6C. There are various others, mostly in components BC-SRV-ALV and BC-ABA-LI - also: I remember that when we upgraded from 4.5B to 4.7C there was an issue with Excel-templates -> the solution was in the release notes somewhere. So, in addition to SMP you might want to check the release notes and/or upgrade guide for solutions.
And yes, moderators ... this is not a security issue, this should go to ECC-Applications/Upgrade. -
Is it possible to display a date as (DD-MON-YYYY) in excel output using excel template in xml publisher where date should be displayed as date only not string.
I've tried to use hierarchy node variables, but it seems like you can't specify a attribute of the hierarchy such as level. So with the WBS hierarchy, if you create a hierarchy node variable, you specify the WBS value to select (If I understand this correctly). I wish I could instead specify "give me all the WBS nodes that happen to have the value of the level attribute greater or equal to 3. If I understand Juergens post, he is saying make security access so that only certain WBS levels can be returned in the query. I suppose we can try that, but that would then preclude getting the level 1 and 2 in the future if the authorization is global.
-
To download the query output to falt file
Hi all,
i have a query which i know will give more than 65k records as the output for a selection.
i cannot run this query in excel due to its limitation.
if i run on web i cannot download this as downloading is happening to excel file only.
The customer ideally wants to download the query result to a text file(csv,tab-delimited etc) which inturn it will upload to MS-Access.
How do i achieve this?
SAP has given response use try using these options:
1.open interfaces to receive the output of a query via the MDX language.
2.open hub tool as it is designed for big amounts of data.(i suppose this is not possible as i want to download query output not the data target contents)
how do i achieve my scenario with option 1?
Are there any alternatives??
Any useful help will be rewarded.
Regards,
Dhanya.hi vivek,
thnks for the useful reply.
i have some problem with my ID,hence loggin in through my coleague's ID.
i will assign u points as i get logged in.
I did as u said by downloading it to unconverted format.
the file got download to a text file.where the output has
1.header rows(10 lines almost)
2.the values r coming in single quotes e,g:
'144000023073 'TAAS SETTLEMENT CONV 738 '19333000 '30.09.2006 '0.000
how can i remove all this?
Regards,
Dhanya
I -
Reports - output to Excel - does not format the "Broken by" rows correctly
Choosing the "break by" column clause while building one of the
wizard based reports works great when you are displaying the
reports in the default HTML mode.
So, my query actually returns a denormalized return set with
multiple rows containing the same fields on certain columns.
This works great with the default format, since the repeated
fields/rows are nulled and I get a neat report.
However, the same thing, if I choose to output in excel, I get
the original denormalized output into the excel document instead
of the null fields for the duplicate fields/columns
It looks like it sends the result set directly to the excel
before allowing the Report UI formatting to take effect. This
is a big issue for us, since we promised the client that we
could get them excel outputs easily, when it does not really
work the way you would expect it.
Any suggestions ??
regards
-AnanthAnanth,
Presently, this is not supported. It is targeted for some future
release. This is a known bug. If you want the bug number then
mail me as it can not be posted here (It is unpublished bug).
Thanx,
Chetan. -
Getting ERROR when downloading alv output to Excel
Hello All,
I get a error message when I try to use the standard funtionality to download the alv output to excel.
The current statement only supports character-type data objects.
What happened?
The current ABAP/4 program "SAPLKKBL " had to be terminated because
one of the statements could not be executed.
This is probably due to an error in the ABAP/4 program.
Error analysis
In statement
"STRLEN( obj )..."
the argument "obj" can only take a character-type data object.
Source code extract
038620 * ansonsten entspricht sich min. Ausgabelänge und Ausprägungslänge
038630 else.
038640 if gs_fc-tech_form ne 99.
> gs_out-hlplen = strlen( ).
038660 endif.
038670 endif.
In this case, the operand "obj" has the non-character type "I".
Please can anyone put some light on this. It is veru difficult to go through the whole std functionality to download.
Thanks for all support guys!
Sri.Hi srikanth,
This error comes because the values present in any one of the displayed coloums containing special character like * present before or after the number.... i.e instead of 4 ...**4.
While displaying in the screen it is of no problem. since both *4 are converted into char format (internally) and gets displayed.
But while you download the same throu the EXCEL functionality SAP will intenally convert the same into NUMERIC format. Since 4 is number.
So in that case *4 will cause dump.
*So find out the place in which the value appearing like this *4 and try to correct it.
*Surely it is of Field LENGTH problem. Try to increase the length of the field 4.
It Should WORK.!!!.. else post ur query here.
REWARD POINTS IF USEFUL
~Lakshmiraj~
Maybe you are looking for
-
Filevault can't be started at MacBook early 2008 in Yosemite
Hi everybody, I can't have filevault started in my MacBook, because as you can see from the below screenshot all the necessary options are greyed out. In an another website I read that repairing permissions and disk can solve this issue. I tried but
-
Having a problem beginning this morning. Checked my AOL mail; unable to remove from trash. When I try to quit mail I get the revolving disc; then I have to use FORCE QUIT in order to get out of mail. Is anyone else having this problem? Any help or id
-
"The storge location for time machine backups can't be found"
I posted this on the TIme capsule forum and got no reply. PLEASE somebody, I need help with this. Time machine on my new MBP (Leopard 10.5.2) is now failing on my new Time Capsule and I am unable to connect to my backups. Whenever I open Time Machine
-
Hi apple. in the Keynotes about the new iphone you say.. 1:28 p.m. Wi-Fi calling is a new feature for making high-quality calls when cell conditions are poor. The question is Work That? i no see the change for me POOR signal here on my office.. my ca
-
Hi, I have implemented reading an XML feed in a Java program using api. In NWDS, I created a Java Project. And as required added 3 externals jar files. I had to import the following: import de.nava.informa.core.ChannelIF; import de.nava.informa.core.