Query Of Queries syntax error. Encountered “local.

Posted: February 22, 2011 in ColdFusion

If you’ve encountered an error “Query Of Queries syntax error. Encountered “local.” while running a Query of a Query in ColdFusion, thanks to Ben Nadel I have the solution.

<cfquery name="local.myQuery" dbtype="query">
SELECT [value]
FROM local.myQueryResults
WHERE [name] = 'Chris'
</cfquery>

Running the above code will error out due to “local” being a reserved keyword in SQL. The solution is to wrap “local” in brackets like “[local]”.

<cfquery name="local.myQuery" dbtype="query">
SELECT [value]
FROM [local].myQueryResults
WHERE [name] = 'Chris'
</cfquery>
Advertisements
Comments
  1. I have encountered a similar error and I am wondering what the solution is.
    Query Of Queries syntax error. Encountered “”

    It looks like it is trying to say a null value has been encountered, but I dont understand where. Any help will be appreciated.

    Michael G. Workman
    michael.g.workman@gmail.com

  2. Jane says:

    Hi there,

    I have this error. Encountered “exists. Incorrect conditional expression, Expected one of [like|null|between|in|comparison] condition,

    Can’t I use not exists in query of query? Thank you, Jane

    select Judicial_ID, Line, Fiscal_Year, Rec_Month, sum(Adj_Amt) Adj_Total
    from adjustments
    where section = ‘Y’
    and complete= ‘C’
    and Fiscal_Year = #Get_Month_Year.Fiscal_Year#
    and Rec_Month = #Get_Month_Year.Record_Month#

    and Judicial_ID in
    (‘ALH’,’ATP’,’LC’,’BH’,’BUR’,’COM’,’DOW’,
    ‘ELA’,’ELM’,’GLN’,’ING’,’LB’,’LA’,’MAL’,
    ‘PAS’,’POM’,’NEW’,’SM’,’SBA’,’CIT’,’WH’)
    group by Judicial_ID, Line, Fiscal_Year, Rec_Month

    select Judicial_ID, Crdf_Linenum, Crdf_Section, Fiscal_Year, Rec_Month, Original_Amt
    from Sections_Data
    where Crdf_Section=’Y’
    and Fiscal_Year = #Get_Month_Year.Fiscal_Year#
    and Rec_Month = #Get_Month_Year.Record_Month#

    and Judicial_ID in
    (‘ALH’,’ATP’,’LC’,’BH’,’BUR’,’COM’,’DOW’,
    ‘ELA’,’ELM’,’GLN’,’ING’,’LB’,’LA’,’MAL’,
    ‘PAS’,’POM’,’NEW’,’SM’,’SBA’,’CIT’,’WH’)

    select Yaccts_Ori_Sums.Judicial_ID,
    Yaccts_Ori_Sums.Crdf_Linenum as fund_name,
    Yaccts_Ori_Sums.Fiscal_Year,
    Yaccts_Ori_Sums.Rec_Month,
    Yaccts_Ori_Sums.original_amt,
    Yaccts_Adj_Sums.adj_total,
    (Yaccts_Ori_Sums.original_amt + Yaccts_Adj_Sums.adj_total) as adjusted_amt
    from Yaccts_Ori_Sums, Yaccts_Adj_Sums
    where Yaccts_Adj_Sums.Judicial_ID=Yaccts_Ori_Sums.Judicial_ID
    and Yaccts_Adj_Sums.Fiscal_Year=Yaccts_Ori_Sums.Fiscal_Year
    and Yaccts_Adj_Sums.Rec_Month=Yaccts_Ori_Sums.Rec_Month
    and Yaccts_Adj_Sums.line=Yaccts_Ori_Sums.crdf_linenum
    union
    select distinct Yaccts_Ori_Sums.Judicial_ID,
    Yaccts_Ori_Sums.Crdf_Linenum as fund_name,
    Yaccts_Ori_Sums.Fiscal_Year,
    Yaccts_Ori_Sums.Rec_Month,
    Yaccts_Ori_Sums.original_amt,
    0.00 as adj_total,
    Yaccts_Ori_Sums.original_amt as adjusted_amt
    from Yaccts_Ori_Sums
    where
    (not exists
    (select ‘X’ from yaccts_adj_sums
    where yaccts_ori_sums.judicial_id = yaccts_adj_sums.judicial_id
    and yaccts_ori_sums.crdf_linenum = yaccts_adj_sums.line
    and yaccts_ori_sums.fiscal_year = yaccts_adj_sums.fiscal_year
    and yaccts_ori_sums.rec_month = yaccts_adj_sums.rec_month)
    )

    and yaccts_ori_sums.judicial_id IN
    (‘ALH’,’ATP’,’LC’,’BH’,’BUR’,’COM’,
    ‘DOW’,’ELA’,’ELM’,’GLN’,’ING’,’LB’,’LA’,’MAL’,’PAS’,
    ‘POM’,’NEW’,’SM’,’SBA’,’CIT’,’WH’)
    and yaccts_ori_sums.Fiscal_Year = 11
    and yaccts_ori_sums.Rec_Month = 6

  3. Gary says:

    Awesome… Saved a lot of head scratching through finding this post, thanks.

    Now if only ACF had decent errors that were in any way descriptive… like say, ‘Local is a reserved keyword’. 😉

  4. Bill says:

    Love it. Thanks for the tip.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s