Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

coldfusion - Inconsistent Q of Q Behaviour

Using ColdFusion Server Enterprise 9,0,1,274733.

Has anyone seen this before? The following code executes without error.

<cfquery name="x" datasource="dw">
select event_code, event_name
from event
</cfquery>

<cfquery name="y" dbtype="query">
select event_code || event_name fred
, event_code
from x
</cfquery>

Two things to notice are that I declared an alias without using the keyword "as", and I used || to concatenate strings. However, if I qualify the first event code, like this:

<cfquery name="y" dbtype="query">
select x.event_code || event_name fred
, event_code
from x
</cfquery>

I get

Query Of Queries syntax error.

Encountered ". Incorrect Select List, Incorrect select column, x.event_code cannot be followed by '||'

There is a similar error if I attempt to declare an alias without the keyword "as".

For the task at hand, I can figure out what to do, but I'm curious if the same thing happens to those of you on Version 10?

Edit starts here

After reading the comments, I tried parentheses. This runs without error.

<cfquery name="y" dbtype="query">
select (x.event_code || event_name) fred
, event_code
from x
</cfquery>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to wrap your statement in () for it to work correctly

SELECT (x.event_code || event_name) fred

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...