Dusty
asked on
cfselect display attribute question
I have a cfselect where I need to concat two variables "AgentFName" "AgentLName" in the display attribute. How can this be done?
<cfquery name="agent" datasource="test">
SELECT fagents.Agent,fagents.Agen tLname,fag ents.Agent FName from fagents
</cfquery>
<cfselect Name = "Agent" query = "agent" value = "Agent" display="AgentFName" queryPosition="below" class="selectpicker show-menu-arrow span4">
<option value=" ">Please Select</option>
</cfselect>
Thanks!
<cfquery name="agent" datasource="test">
SELECT fagents.Agent,fagents.Agen
</cfquery>
<cfselect Name = "Agent" query = "agent" value = "Agent" display="AgentFName" queryPosition="below" class="selectpicker show-menu-arrow span4">
<option value=" ">Please Select</option>
</cfselect>
Thanks!
ASKER
Hi gdemaria,
When I run that I get no error, but each record is displayed as 0.0 ?? what could cause that? See attached pic."
<cfquery name="agent" datasource="test">
SELECT fagents.Agent,fagents.Agen tLname + ' ' + fagents.AgentFName as Name from fagents
</cfquery>
<cfselect Name = "Agents" query = "agent" value = "Agent" display="Name" queryPosition="below" class="selectpicker show-menu-arrow span4">
<option value=" ">Please Select</option>
</cfselect>
When I run that I get no error, but each record is displayed as 0.0 ?? what could cause that? See attached pic."
<cfquery name="agent" datasource="test">
SELECT fagents.Agent,fagents.Agen
</cfquery>
<cfselect Name = "Agents" query = "agent" value = "Agent" display="Name" queryPosition="below" class="selectpicker show-menu-arrow span4">
<option value=" ">Please Select</option>
</cfselect>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm using MySQL I will try what you suggested. Thanks!
Check out the Concat_WS function for MySQL:
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat-ws
CONCAT_WS(',', 'fagents.AgentLname', 'fagents.AgentFName') as Name
There is also the Concat function:http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
ASKER
SELECT fagents.Agent, CONCAT(fagents.AgentLname, ' , ',fagents.AgentFName) as Name from fagents
Worked! Thanks again
Worked! Thanks again
> each record is displayed as 0.0 ?? what could cause that?
FWIW, it's because MySQL only uses "+" for addition. If you use it with strings, MySQL attempts to convert the strings to numbers first. Since a name like "John" or "Smith" isn't a number, MySQL converts it to zero.
SELECT 'John' + 'Smith' AS Name <== translates to SELECT '0' + '0' AS Name
The behavior's similar to CF's Val() function. Val() converts any non-numeric values to 0.
FWIW, it's because MySQL only uses "+" for addition. If you use it with strings, MySQL attempts to convert the strings to numbers first. Since a name like "John" or "Smith" isn't a number, MySQL converts it to zero.
SELECT 'John' + 'Smith' AS Name <== translates to SELECT '0' + '0' AS Name
The behavior's similar to CF's Val() function. Val() converts any non-numeric values to 0.
<cfquery name="agent" datasource="test">
SELECT f.Agent
,f.AgentLname + ' ' + f.AgentFName as AgentFName
from fagents
</cfquery>