I'm kind of doing this with a project... in a process, I have a query that is VERY varied, depending on various factors, so there's lots of ifs, switch/cases, etc. that determine the query in the end.
What I do is (like some others have mentioned) build up a string variable with the query code... <cfset querycode = "select * from table"> <cfif blah> <cfset querycode = querycode & "where blah = blah"> <cfelseif blah2> <cfset querycode = querycode & "where blah2 = blah2"> </cfif> etc. etc. You get the idea. I then can both execute that query straight up: <cfquery datasource="whatever"> #querycode# </cfquery> and I also store it in my DB for later retrieval and execution (like above). Someone else mentioned the single quote issue - I bumped into that. What I did was do a Replace on my query variable with something unusual, three ampersands; <cfset querycode = Replace(querycode, "'", "&&&", "ALL")> and stored it in the DB. When I pull it back out of my DB, I reverse the Replace() call. Works like a champ. At 11:02 AM 2/14/2003 -0500, you wrote: >I have a question. I have a query that is built depending on many things, >the where statement, order by, actual columns asked for that kinda >thing..... I want to save what the actual sql text is that ran that >query. Like what you can see in the debugging code. Does this make >sense? Any help would be great. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4