cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a table using the the output result of a stored procedure?

Former Member
6,572

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.

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

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.)

Answers (3)

Answers (3)

thomas_duemesnil
Participant

If you are in iSQL you could use

describe PROCEDURE MyCoolProcedure
Former Member
0 Kudos

Why this does not work?

describe PROCEDURE dbo.getMsgList;


Could not execute statement.

incrrect syntax near the keyword "PROCEDURE".

Sybase error code=156,SQLstate='ZZZZZ'.

VolkerBarth
Contributor
0 Kudos

What version are you using?

AFAIK, the Interactive SQL DESCRIBE statement is available since v10 and does only work with DBISQL, not with dbisqlc.

VolkerBarth
Contributor
0 Kudos

@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.

Former Member
0 Kudos

select @@version

Adaptive Server Enterprise/15.0.2/EBF14332/P/NT(I*86)/Windows2000....

VolkerBarth
Contributor
0 Kudos

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.

Former Member

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;
VolkerBarth
Contributor
0 Kudos

An in-depth addition to the topic, of course:)

It should be noted that both system procedures require v12 and above, AFAIK.

Breck_Carter
Participant
0 Kudos

It should also be noted that it requires SQL Anywhere 🙂

justin_willey
Participant
0 Kudos

maybe time for a feature request:

ALTER DATABASE SET RDMS = 'SQLANYWHERE'

🙂

VolkerBarth
Contributor
0 Kudos

As default, right?

Breck_Carter
Participant
0 Kudos

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...

VolkerBarth
Contributor
0 Kudos

Who's ASE in the image? The one standing in the middle?

Breck_Carter
Participant
0 Kudos

No, that's me... the other two are you and Ivan 🙂

VolkerBarth
Contributor
0 Kudos

I must be getting old - can't remember the scene and the cause...

select *
  into dba.MyNewTable
  from dba.MyCoolProcedure()
 where 0 = 1
Former Member
0 Kudos

This does not work either?

select *

into dba.MyNewTable

from dbo.getMsgList()

where 0 = 1


Could no execute statement.

incrrect syntax near ")".

Sybase error code=102,SQLstate='4200'

Breck_Carter
Participant
0 Kudos

What database software are you using? I don't think you are using any version of SQL Anywhere, which is what this forum is all about.

Former Member
0 Kudos

select @@version

Adaptive Server Enterprise/15.0.2/EBF14332/P/NT(I*86)/Windows2000....

Breck_Carter
Participant
0 Kudos

This is the wrong forum to ask about ASE, sorry.

VolkerBarth
Contributor
0 Kudos

Yes, already noted in the comments on Thomas's answer...

VolkerBarth
Contributor
0 Kudos

Besides that, I'm glad the question was raised here - the SQL Anywhere-related answers are very helpful.