Re: PREPAREd statement
Posted in 1996
In <32540EED.61C7@luminous-chao.com> Christopher Sharrer <chris@luminous-chao.com> writes: >Ramiro Rela wrote: >> >> First, sorry about my very poor english. At least you have a second language. In Australia, most of us are barely able to speak just the one. >> >> I have the following problem: >> >> I need to EXECUTE a PREPAREd statement from a string like >> >> "UPDATE mytable >> SET (first, second, third, fourth) = (myrec.first, myrec.second, >> myrec.third, myrec.fourth) >> WHERE ever " >> >> Beeing 'myrec' a program record holding data to update into 'mytable' >> >> The error is: >> "table myrec not found in database" (or something similar). >> >Your English is better than most Americans! Or, your American is better than most English, depending on the strength of your convictions. :) >You need either: >LET sqltext = > "UPDATE mytable ", > "SET (first, second, third, fourth) = (", > myrec.first, ", ", > myrec.second, ", ", > myrec.third, ", ", > myrec.fourth, ")", > " WHERE ever " >PREPARE sqlstmt FROM sqltext >EXECUTE sqlstmt Spot on. Although if myrec.* are CHAR variables, you may need to expand this slightly by including the quotes ; let sqltext = "UPDATE mytable ", "SET (first, second, third, fourth) = (", "'", myrec.first, "', ", "'", myrec.second, "', ", "'", myrec.third, "', ", "'", myrec.fourth, "')", " WHERE ever " Looks like a mess, I know, but the idea is to get a string (sqltext) that is the exact literal value to be EXECUTED. Believe me, once you get the hang of putting them together, they're not hard, and they are a decent way of constructing dynamic SQL statements. Bryan Tonnet batonnet@zeta.org.au