Skip to main content
Known Participant
May 15, 2008
Question

Storing database output in a variable

  • May 15, 2008
  • 3 replies
  • 701 views
Hi all!

I cannot find the answer to this question ANYWHERE in any book or on the Internet so here goes!

I want to store the output from a database query into a variable. Thats it! Sounds simple right? Nope, its the hardest thing ever.

This is my query:

<cfquery name="rsProductRange" datasource="01">
SELECT s1.PartNo
FROM dbo.Stage s1
WHERE s1.Manufacturer = 'Acer'
</cfquery>

I want to store the PartNo values into a variable as a single string. So for example, the PartNo outputs would be 54.QJ91K.UC5, 66.QJ02K.UC6, 32.QJ13K.UC7, 49.QJ37K.UC8.

I assumed that to store these values as a string into a variable, I would do this:

<cfset PartNos = <cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ;</cfoutput> >

but the above doesn't work, because it can't "read" the <cfoutput query> bit onwards and causes errors.

However if I just place <cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ; </cfoutput> within my HTML code, it outputs perfectly all the part numbers in a list seperated by a semi-colon.
This topic has been closed for replies.

3 replies

BKBK
Community Expert
Community Expert
May 17, 2008
Solaced wrote:
I assumed that to store these values as a string into a variable, I would do this:

<cfset PartNos = <cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ;</cfoutput> >


I suspect what you're thinking of is

<cfsavecontent variable="PartNos">
<cfoutput query="rsProductRange">#rsProductRange.ManfPartNo# ;</cfoutput>
</cfsavecontent>




solacedAuthor
Known Participant
May 20, 2008
Many thanks for the replies guys. I've downloaded the material in PDF format that BKBK kindly suggested.

I have got the Ben Forta books for ColdFusion MX 7, but he didn't discuss my type of situation anywhere and you need to know what you're looking for before you can find it in the reference section.

I have used the ValueList() operation and it works perfect. Thank you!
BKBK
Community Expert
Community Expert
May 17, 2008
Solaced wrote:
> Thank you for the reply. Which docs are you referring to? I
> searched online through Adobe but there was no mention of this.


Online: Coldfusion 8 documentation

Offline: {your_CF8_installation_dir}\wwwroot\cfdocs\dochome.htm



Inspiring
May 15, 2008
<cfset myvar = valuelist(queryname.columnname)>

it's all in the docs... just look.

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
solacedAuthor
Known Participant
May 15, 2008
Thank you for the reply. Which docs are you referring to? I searched online through Adobe but there was no mention of this.
Inspiring
May 15, 2008
quote:

Originally posted by: solaced
Thank you for the reply. Which docs are you referring to? I searched online through Adobe but there was no mention of this.

Google can be your freind if you know what you are looking for. Common search strings are:
<cfNameOfTag> x
coldusion NameOfFunction x
coldfusion TypeOfFunction functions

x is the cf version number you are running, and is optional. Function types include date, string, and list.

ValueList, which is what you were looking for, is a query function.