tags:

views:

28

answers:

2

How do I execute a Sybase query which is stored in a column of another Sybase table?

Suppose that "SELECT COLa FROM TABLE_A" is stored in a column called 'command' in a separate table (table_log). I want to find a way that allows me to execute this query and get the answer.

A: 

Try looking for

execute immediate

I'm not familiar with sybase but in Oracle it would be something like the following:

declare
    query varchar2(1000);
begin
    select val from saved_query into query;
    execute immediate query;
    commit;
end;
Jerome
thank you very much i think this will help me a lot, thank you again:-)
choi
A: 

Try:

create table test_table(f1 varchar(64))
insert into test_table values( "select getdate()" )
go
declare @myvar varchar(30)
select @myvar=f1 from test_table
execute(@myvar)
go
obiwan2u