Solved

How to convert dynamically a query row to a list, in Coldfusion

Posted on 2014-10-02
2
604 Views
Last Modified: 2014-10-02
Hi experts,

I have to loop into a query and to output data to a csv file.

My problem is that I want to get the full record (row) and have the different values separate by a semi-colon.
But I can just do something like the following, because there are commas into the data.
<cfset variables.values = replace(variables.getData.currentRow, ",", ";")>

Open in new window


Do you know a trick to achieve this ? Thanks a lot.

Here is the code I’m trying to use :
<cfquery name="variables.getData" datasource="joecool_web">
	select * from jcstktabl where jcid = '#listgetAt('#variables.index#',1, ';')#'
</cfquery>
<!--- build the product’s file --->
<cfif variables.getData.RecordCount NEQ 0>
	<cfset variables.values = replace(variables.getData.currentRow, ",", ";")>
	<cffile action="append" file="#variables.productsFile#" output="#variables.values#" addnewline="true" charset="iso-8859-1">
</cfif>

Open in new window

0
Comment
Question by:adam1h
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40357024
Not sure what you're trying to do here, the value of getData.currentRow is a number indicating the record number of the current row; 1,2,3.... etc.

<cfset variables.values = replace(variables.getData.currentRow, ",", ";")>

You may want something like this to create a quoted, comma delimited list..

<cfset variables.values = QuotedValueList(variables.getData)>
0
 

Author Comment

by:adam1h
ID: 40357056
Hi gdemaria,

Indeed, I misunderstood the currentrow function.

Knowing this, coupled with this infos (source), I have correct the statement as follow :
<cfquery name="variables.getData" datasource="joecool_web">
	select * from jcstktabl where jcid = '#listgetAt('#variables.index#',1, ';')#'
</cfquery>
<!--- build the product’s file --->
<cfif variables.getData.RecordCount NEQ 0>
	<cfset variables.values = "">
	<cfloop index="variables.ColumnName" list="#variables.getData.ColumnList#">
		<cfset variables.values &= variables.getData[variables.ColumnName][variables.getData.currentRow]>
	</cfloop>
	<cffile action="append" file="#variables.productsFile#" output="#variables.values#" addnewline="true" charset="iso-8859-1">
</cfif>

Open in new window


I will test it but I think it’s that good way to do it.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question