首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 其他服务器 >

[]构造sql语句时发生蹊跷的异常

2012-02-26 
[求助]构造sql语句时发生蹊跷的错误我的思路是这样的,构造字符串sCalcFields,以此作为sql查询语句的字段。

[求助]构造sql语句时发生蹊跷的错误
我的思路是这样的,构造字符串sCalcFields,以此作为sql查询语句的字段。但运行时发生错误,信息如下:

Error Executing Database Query.  

Query Of Queries syntax error.
Encountered "(. Incorrect Select Statement, Expecting a 'FROM', but encountered '(' instead, A select statement should have a 'FROM' construct.

498 : <cfquery name="rsS" dbtype="query">
499 : select #sCalcFields# from rs
500 : </cfquery>

SQL select sum(yns_1) as yns_1,sum(yns_1c) as yns_1c,sum(yns_1a) as yns_1a,decode(sum(yns_1),0,null,sum(yns_1a)/sum(yns_1))*100 as yns_1p,sum(yns_2) as yns_2,sum(yns_2c) as yns_2c,sum(yns_2a) as yns_2a,decode(sum(yns_2),0,null,sum(yns_2a)/sum(yns_2))*100 as yns_2p from rs  

但是,我在toad中,直接执行
select sum(yns_1) as yns_1,sum(yns_1c) as yns_1c,sum(yns_1a) as yns_1a,decode(sum(yns_1),0,null,sum(yns_1a)/sum(yns_1))*100 as yns_1p,sum(yns_2) as yns_2,sum(yns_2c) as yns_2c,sum(yns_2a) as yns_2a,decode(sum(yns_2),0,null,sum(yns_2a)/sum(yns_2))*100 as yns_2p from (在此将rs替换为具体的select语句),是没有问题的。

另还发现,如果将sCalcFields构造成不使用decode的字符串:如
sum(yns_1) as yns_1,sum(yns_1c) as yns_1c,sum(yns_1a) as yns_1a,sum(yns_1a)/sum(yns_1)*100 as yns_1p,sum(yns_2) as yns_2,sum(yns_2c) as yns_2c,sum(yns_2a) as yns_2a,sum(yns_2a)/sum(yns_2) as yns_2p 
程序就能正常运行了,求助各位大侠,怎么回事呢?我还是希望使用decode判断的

[解决办法]
Query in Query的功能有限的.很多在SQL里支持的在Query in Query是不支持的.

热点排行