dbTalk Databases Forums  

Dynamic query

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Dynamic query in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
janis
 
Posts: n/a

Default Dynamic query - 11-12-2009 , 02:02 AM






Hi ,
I'am trying to create a query with dynamic columns:

ALTER PROCEDURE "DBA"."DynamicTest"( in col varchar(50) )

BEGIN

declare @str varchar(1000);
set @str='select '+col+' from tblB;
execute immediate @str;

END

But iam getting an error:
You attempted to execute a SELECT statement in a context where a
result set is not permitted.
What am i doing wrong ?

Janis

Reply With Quote
  #2  
Old   
janis
 
Posts: n/a

Default Re: Dynamic query - 11-12-2009 , 02:18 AM






Ok, i figure it out myself, I forgot to put the result into a
temptable BUT i dont want my query in a temporary table , I just want
a stored procedure where I can put dynamic columnnames and get the
results by calling the stored proc.

Reply With Quote
  #3  
Old   
Reg Domaratzki [Sybase iAnywhere]
 
Posts: n/a

Default Re: Dynamic query - 11-12-2009 , 08:07 AM



janis wrote:
Quote:
Ok, i figure it out myself, I forgot to put the result into a
temptable BUT i dont want my query in a temporary table , I just want
a stored procedure where I can put dynamic columnnames and get the
results by calling the stored proc.
What version of SQL Anywhere are you using? Starting at v901, the
execute immediate command includes a "WITH RESULT SET" clause that
sounds like it will suit your needs.

--
Reg Domaratzki, Sybase iAnywhere Solutions
Please reply only to the newsgroup

Documentation : Exercise your WRITE @DocCommentXchange: DCX.sybase.com
SQL Anywhere Patches and EBFs : http://downloads.sybase.com/swd/base.do
-> Choose SQL Anywhere
-> Optionally set filter to "Display ALL platforms IN ALL MONTHS"

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.