Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...