cancel
Showing results for 
Search instead for 
Did you mean: 

How do I go about sending the results from a stored procedure to a text file in SQL Anywhere ?

tjhastings
Explorer
0 Kudos

for example

CREATE PROCEDURE "DBA"."usp_TestOutput"()

BEGIN

DECLARE sqlTxt VARCHAR(4096);

SET sqlTxt = 'SELECT * from SYCONFIG; SELECT sys_Key from SYCONFIG'; EXECUTE IMMEDIATE WITH RESULT SET ON sqlTxt;

SET sqlTxt = 'SELECT sys_Key from SYCONFIG';

EXECUTE IMMEDIATE WITH RESULT SET ON sqlTxt;

END

BEGIN

EXECUTE "DBA"."usp_TestOutput";

output to 'C:\Test.out'

END;


Returns and error at output, I have tried other methods as well like using UNLOAD to no luck/


Can someone give me a direction please.


Thanks Terry

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Active Participant
0 Kudos

UNLOAD SELECT ... should work here, without need to use dynamic SQL. The filename can be specified via variable as well. OUTPUT is an ISQL command and therefore cannot be used within code blocks.

Such as

UNLOAD SELECT sys_Key FROM SYCONFIG TO 'C:\\Test.txt' FORMAT TEXT;

----

FWIW, I recommend to ask your question in the SQL Anywhere Forum (which has a number of questions related to OUTPUT/UNLOAD), because the current changes in the SAP Community (aming others, the dropped SQL Anywhere topic page) bear the risk that your questions may become invisible to the relevant experts.

Answers (0)