Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Create field list as a string in Query of Query

Community Beginner ,
Feb 17, 2012 Feb 17, 2012

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.

697
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2012 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 17, 2012 Feb 17, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources