CFset string concatenation (of query results)

11,782

Solution 1

If you really need an additional variable, ColdFusion's concatenation operator is &

 <cfset teacherName = Firstname &" "& Lastname>

Though for simple output, no extra variable is needed. Just output the column values:

<cfoutput query="getName">
   #Firstname# #Lastname# <br>
</cfoutput>

Solution 2

try using <cfset teacherName= Firstname & " " & Lastname>

Solution 3

As an alternative to using the ColdFusion & or &= string operators, you can also do the following:

<cfoutput query="getName">
    <cfset myName="#Firstname# #Lastname#">
    <p>#myName#</p>
</cfoutput>
Share:
11,782

Related videos on Youtube

redconservatory
Author by

redconservatory

Updated on June 04, 2022

Comments

  • redconservatory
    redconservatory almost 2 years

    Is it possible to set a ColdFusion variable to a concatenated string?

    <cfoutput query="getName">
       <cfset myName=#Firstname# #Lastname#>
    </cfoutput>
    

    Doesn't seem to work, nor does

    <cfoutput query="getName">
       <cfset teacherName=#Firstname# + #Lastname#>
    </cfoutput>
    
  • Leigh
    Leigh over 12 years
    Edited to remove extraneous pound signs