on 2011 Jun 30 5:28 PM
How to create a table using the the output result of a stored procedure?
My purpose is getting the output data type of a stored procedure.
Request clarification before answering.
If I do understand you correctly, you want to get the data types of the result set of a stored procedure (instead of the result set itself). You can use the sa_describe_query() system procedure when using v10 or newer, e.g.
select * from sa_describe_query('select * from sa_conn_info()')
Or you can query the system catalog directly, such as
select parm_name, * from sysprocparm spp key join sysprocedure sp where parm_type = 1 and proc_name = 'sa_conn_info' order by 1
(For older versions, the query might have to be adapted.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you are in iSQL you could use
describe PROCEDURE MyCoolProcedure
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What version are you using?
AFAIK, the Interactive SQL DESCRIBE statement is available since v10 and does only work with DBISQL, not with dbisqlc.
@qkc1828: I turned your "answers" into comments to the according answers - IMHO this makes it far easier to follow a discussion thread. You can add comments (instead of answes) by using the "add new comment" button right beneath any question/answer.
Glad that I've asked for the version:)
Please note, this is a forum on Sybase SQL Anywhere, not Sybase ASE, which is a different database product.
I would suggest to have a look at on one of Sybase's ASE newsgroups - see this link.
The above answers work nicely for procedures that have a single result set where the server is able to determine the schema for the result set when the procedure is created. This could be because the procedure describes the columns using a RESULT clause or because the server is able to determine the result set by inspecting the procedure. In the case of multiple result sets or procedures where the schema changes from call to call, you could use instead the sa_describe_cursor system procedure. This system procedure describes the current result set of an open cursor, which could be a cursor over a CALL statement. You can even use this if the procedure returns multiple result sets; just use RESUME until the cursor is positioned on the proper result set. However, unlike the other answers, this approach requires actually executing the procedure.
The sa_copy_to_temp_table system procedure can also be used if you want to copy the contents of the cursor to a temporary table (although the column names are generated as col1..colN instead of coming from the statement).
create temporary procedure P_DynamicResult( @type int ) begin if @type = 1 then select * from sys.systab; else select * from dbo.rowgenerator; end if; end; begin declare crsr cursor for call P_DynamicResult(0); open crsr; select * from sa_describe_cursor('crsr'); close crsr; end;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Too funny... a question about ASE gets a "Popular Question" badge, and answer about SQL Anywhere gets selected as the correct answer 🙂 http://4.bp.blogspot.com/_qQmMZeCw7l4/TPjb1clQzcI/AAAAAAAAAAQ/5O468-VilB8/s1600/Three%2BStooges%2BMo...
select * into dba.MyNewTable from dba.MyCoolProcedure() where 0 = 1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.