Skip to main content
Inspiring
February 17, 2012
Question

Create field list as a string in Query of Query

  • February 17, 2012
  • 2 replies
  • 718 views

Can you please correct this query

<cfquery name="getView" datasource="#Application.DSN_GDX#">

select * from vstr_entity_mast_y where tax_year=2011

</cfquery>

<cfset checkedImgStr = "<img src=../stir_images/checked.jpg>">

<cfset loopStr = "">

<cfset variables.listIds = "BNSR,BNSS,VIEW">

<cfloop index="Fld" list="#variables.listIds#">

<cfset loopStr = loopStr&'<img src=../stir_images/checked.jpg>'& " as [#Fld#],">

</cfloop>

<cfset P_loopStr = replace(loopStr, "<img src=../stir_images/checked.jpg>", "'<img src=../stir_images/checked.jpg>'", "all")>

<cfquery name="getPrivByUser" dbtype="query">

select entity_id, entity_name,#P_loopStr# leid

from getView

</cfquery>

I am getting this error:

Encountered "<. Incorrect Select Statement, Expecting a 'FROM', but encountered '<' instead, A select statement should have a 'FROM' construct.

This topic has been closed for replies.

2 replies

Inspiring
February 17, 2012

output your variable and see what it ends up being.  put it in a pre tag to make sure the angle bracket shows up.

BKBK
Community Expert
Community Expert
February 17, 2012

In  view of the comma at the end of loopStr, I will assume that leid is a column name. Then the likely cause of the error is ColdFusion escaping the single quotes you added. To prevent this, modify the select statement to

select entity_id, entity_name,#preserveSingleQuotes(P_loopStr)# leid