Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004

    Unanswered: store procedure problems~

    I am using Sybase IQ Server 14.3 and I have declare a variable in a store procedure.
    For example :
    declare @stmt varchar(100)
    select @stmt = @stmt +' select * from tb1'
    at the end of the store procedure, I want to execute this variable, i.e, I want to do the query 'select * from tb1', but of course I can't just type select * from tb1 at the end coz the query must generated dynamic. I know that in SQLServer, I can use Exec (@stmt) to do that, but it seems it doesn't work in IQ.
    What should I do? Is it possible for me to do that in IQ?
    Thanks in advance~

  2. #2
    Join Date
    Jul 2004
    You should run :
    execute immediate @stmt;

    But in proc, dinamic query not return more than 1 record. So you should insert into temp table and then select from temp table.

    create procedure t (@id integer)
    declare @sql varchar(200);
    set @sql = 'select * into #temp from table t1 where id = ' || trim(@ID);
    select * from #temp;

    Good luck,
    Thi Nguyen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts