Re: Q: FROM clause of SELECT statement?
Posted in 1997
Arun Jamwal <jamwal@quality.com> wrote: :I want to do a SELECT where FROM table-name is unknown :until the runtime. The sample code follows: What language is this? It sure isn't Informix stored procedure language that works in my ver. 7.10.UC1 OnLine. :create procedure stp_gettablename () :as :begin : : declare @tab_name varchar(255) : : declare tname_cur cursor for : select @tab_name from list_id : : open tname_cur : : fetch tname_cur into @tab_name : : select * from @tab_name : --------------------complains about non-static name :end : : : :Can it be done somehow? Any tips/hints would be welcome! Even if you changed this into Informix SPL it couldn't be done because you can do nothing but use the ? in a statement to make it dynamic. The ? can only be used for values in the where clause and not for the likes of tablenames in the from clause. You can also not build sql statements in code and have them executed as you can in 4GL, NewEra, ESQL/C, Java and other languages. This is very unfortunate, but it's the way the spl is designed. What you want to do can of course easily be done in a program the executes sql against the database. You do however have to create the statement in a string (or char variable), prepare that, declare a cursor on the prepared statement and fetch the data. Nils.Myklebust@idg.no NM Data AS, P.O.Box 9090 Gronland, N-0133 Oslo, Norway My opinions are those of my company The Informix FAQ is at http://www.iiug.org