Re: SQLin 4GLNot Working ......
Posted in 1997
John Cokos <jcokos@ix.netcom.com> wrote: : I'm having trouble with the following statement.... : : LET cTable = "customers" : SELECT count(*) INTO nCount FROM cTable : WHERE status = "DEAD" : : I get an error stating that cTable is not in the database. Yes of course. That's what you have written. RTFM on this. : I have tried the following, with the same results. : LET cSQL = "SELECT count(*) FROM ", cTable : " WHERE status = ", "\\"" DEAD, "\\"" : PREPARE qSQL FROM cSQL : DECLARE q_cur CURSOR FOR qSQL : FOREACH q_cur INTO nCount : END FOREACH This is correct and should work, but you may have one " too many (just before DEAD). I dislike the \\ to much to ever have used it, so I am not sure. You might want to use 'set explain on' to see what is generated in the sqexplain.out file. Errors are often easier to spot there. Just for your information I would have written the above as follows: LET cSQL = "SELECT count(*) FROM ", cTable clipped, -- Added clipped above to avoide many spaces in the cSQL string. " WHERE status = 'DEAD'" -- Use single quotes - ansi standard and no need to escape with \\ -- Single quotes *may* not work in early versions of the engine. prepare qSQL from cSQL declare q_cur cursor for qSQL open q_cur fetch q_cur into nCount close q_cur open/fetch/close is the same as foreach so it's a matter of preference what you use. I like open/... when only one row is returned. : If I do a ... MESSAGE cSQL after the above code, the select :statemente is correct : (customers appears, not cTable) : : What am I missing here? 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