Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a variable's name using a variable....

Status
Not open for further replies.

ScottNeth

Technical User
Mar 11, 2002
44
US
I have an interesting delimma - I'm attempting to build a universal reporting tool for our orders that can expand as the tool expands (columns added for new product types, etc.).
I went into the system key and pulled all of the column names for my ordering table (dbo.telcondet) and placed the column names into a table named dbo.Conduit_ColumnNames -- I have this set to update as new columns are added, etc. That's working fine.
Now, with a list of the dbo.Conduit_ColumnNames, I can create forms on the previous page where my users can select what values they what output into a table (that is, what columns to choose in telcondet - or the SELECT statement for the query, which is output as a variable). So far, so good.
For the WHERE statement, I was originally checking every attribute possibility like this example:


<cfif IsDefined(&quot;form.ProbabilityOfClose&quot;)>
<cfset ProbabilityOfClose = &quot;and ProbabilityOfClose IN (#form.ProbabilityOfClose#)&quot;>
<cfelse>
<cfset ProbabilityOfClose = ''>
</cfif>

<cfif IsDefined(&quot;form.ExpMonthClose&quot;)>
<cfset ExpMonthClose = &quot;and ExpMonthClose IN (#form.ExpMonthClose#)&quot;>
<cfelse>
<cfset ExpMonthClose = ''>
</cfif>
....ect. ect.

I soon realized I was writing the same statement over and over and only changing what could be pulled from a <cfloop of the column names. This is where I ran into problems. I attempted to substitute ProbabilityOfClose, ExpMonthClose etc. like the following:

<cfloop query = &quot;rsProducts&quot;>
<cfif IsDefined(&quot;form.Subsidiary&quot;)>
<cfset #rsProducts.ColumnName# = &quot;and #rsProducts.ColumnName# IN (#form.#rsProducts.ColumnName##)&quot;>
<cfelse>
<cfset #rsProducts.ColumnName# = ''>
</cfif>
</cfloop>

It doesn't working. I get an invalid parser construct right at the third line where the period is. Additionally, for the table output, I have the exact same issue (see full code below). I have tried every way of concatanation I can think of, and I cannot get it to work. I really want to be able to build the table like this, rather than have to go in and hard code the entire table as it will expand and contract.

The full code is listed below as I wished for it to work:


<cfinclude template=&quot;../../../Connections/connCONMKTSL02.cfm&quot;>
<!---set SelectOutput to single quotes for the select statment--->
<cfset SQSelect = #replace(form.selectOutput,&quot;'&quot;,&quot;&quot;,&quot;all&quot;)#>

<!---Selects all of the column headers and column names based on columns chosen on previous page--->
<cfquery name=&quot;rsProducts&quot; datasource=#MM_connCONMKTSL02_DSN# username=#MM_connCONMKTSL02_USERNAME# password=#MM_connCONMKTSL02_PASSWORD#>
SELECT ColumnName, CommonName FROM dbo.Conduit_ColumnNames WHERE ColumnName IN (#PreserveSingleQuotes(selectOutput)#)
</cfquery>

<!---Sets all of the Where variables--->
<cfloop query = &quot;rsProducts&quot;>
<cfif IsDefined(&quot;form.Subsidiary&quot;)>
<cfset #rsProducts.ColumnName# = &quot;and #rsProducts.ColumnName# IN (#form.#rsProducts.ColumnName##)&quot;>
<cfelse>
<cfset #rsProducts.ColumnName# = ''>
</cfif>
</cfloop>

<!---pulls from main record table columns based on previous select--->
<cfquery name=&quot;rsTecondetPull&quot; datasource=#MM_connCONMKTSL02_DSN# username=#MM_connCONMKTSL02_USERNAME# password=#MM_connCONMKTSL02_PASSWORD#>
SELECT #SQSelect# FROM dbo.telcondet
WHERE drecvd BETWEEN '#form.Date1#' AND '#form.Date2# 11:59:59 PM' <cfloop query = &quot;rsProducts&quot;>#PreserveSingleQuotes(rsProducts.ColumnName)#</cfloop>
</cfquery>

<cfscript>
rsProducts_NumRows = rsProducts.RecordCount;
</cfscript>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>

<table border=&quot;1&quot; cellspacing=&quot;1&quot; cellpadding=&quot;4&quot;>
<!---column headers--->
<tr><cfoutput query=&quot;rsProducts&quot;>
<td bgcolor=&quot;##3366CC&quot;><font face=&quot;Arial, Helvetica, sans-serif&quot; color=&quot;##CCCCCC&quot;>#rsProducts.CommonName#</font></td>
</cfoutput> </tr>

<!---Output of query--->
<cfoutput query = &quot;rsTecondetPull&quot;>
<tr>
<cfloop query = &quot;rsProducts&quot;>
<td><font face=&quot;Arial, Helvetica, sans-serif&quot;> #rsTelcondet.#ColumnName##</font></td>
</cfloop>
</tr>
</cfoutput>
</table>
</body>
</html>

Scott Neth
Web Designer/Cyberpunk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top