Unix Technical Forum

How to get around a stored procedure returning a datasset that runs adynamic sql which changes the number (and names of) columns

This is a discussion on How to get around a stored procedure returning a datasset that runs adynamic sql which changes the number (and names of) columns within the Sybase forums, part of the Database Server Software category; --> Given the following sql:- create procedure sp2 (in @param integer) begin declare @sql varchar(100); if @param = 1 then ...


Go Back   Unix Technical Forum > Database Server Software > Sybase

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-04-2008, 04:26 PM
eahofer4groupposting@gmail.com
 
Posts: n/a
Default How to get around a stored procedure returning a datasset that runs adynamic sql which changes the number (and names of) columns

Given the following sql:-

create procedure sp2 (in @param integer)
begin
declare @sql varchar(100);
if @param = 1 then
set @sql = 'select 1 as a '
else
set @sql = 'select 2 as b, 3 as c ' //ATTEMPT 1
//ATTEMPT 2 set @sql = 'select 4 as b'
end if;
execute immediate with results on @sql
end

On execution, one gets the following results:-
call sp(1) //works, get column labelled "a" and 1
call sp(2) //fails

Revise the sql, commenting out ATTEMPT 1 and enabling ATTEMPT2
call sp(1) // works
call sp(2) // works, BUT the column name is "a" not b.

Now, what I'm wanting to do is change the result set... I know that
if I have some sort of trigger to call a different result set, I can
have 2 different results - but the column titles still don't change.

I've tried this in SP and TRANSACT dialects; I've tried putting the
values into a temp result set; I've tried deleting the #temp table ...

How do I get this to work so that I can vary the number of columns and
their labels?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-04-2008, 04:26 PM
Luc
 
Posts: n/a
Default Re: How to get around a stored procedure returning a datasset that runs a ?dynamic sql which changes the number (and names of) columns


Is this ASA syntax ?




eahofer4groupposting@gmail.com wrote:
> Given the following sql:-
>
> create procedure sp2 (in @param integer)
> begin
> declare @sql varchar(100);
> if @param = 1 then
> set @sql = 'select 1 as a '
> else
> set @sql = 'select 2 as b, 3 as c ' //ATTEMPT 1
> //ATTEMPT 2 set @sql = 'select 4 as b'
> end if;
> execute immediate with results on @sql
> end
>
> On execution, one gets the following results:-
> call sp(1) //works, get column labelled "a" and 1
> call sp(2) //fails
>
> Revise the sql, commenting out ATTEMPT 1 and enabling ATTEMPT2
> call sp(1) // works
> call sp(2) // works, BUT the column name is "a" not b.
>
> Now, what I'm wanting to do is change the result set... I know that
> if I have some sort of trigger to call a different result set, I can
> have 2 different results - but the column titles still don't change.
>
> I've tried this in SP and TRANSACT dialects; I've tried putting the
> values into a temp result set; I've tried deleting the #temp table ...
>
> How do I get this to work so that I can vary the number of columns and
> their labels?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:13 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com