简体   繁体   English

空字符串查询的Coldfusion查询

[英]Coldfusion Query of Queries with Empty Strings

The query I start out with has 40,000 lines of empty rows, which stems from a problem with the original spreadsheet from which it was taken. 我开始的查询有40,000行空行,这是由于原始电子表格存在问题。

Using CF16 server 使用CF16服务器

I would like to do a Query of Queries on a variably named 'key column'. 我想对一个变量命名的“键列”进行查询。

In my query: 在我的查询中:

var keyColumn = "Permit No."

var newQuery = "select * from source where (cast('#keyColumn#' as varchar) <> '')";

Note: the casting comes from this suggestion 注意:强制转换来自建议

I still get all those empty fields in there. 我仍然在那里找到所有那些空字段。

But when I use "City" as the keyColumn, it works. 但是,当我使用“城市”作为keyColumn时,它可以工作。 How do the values in both those columns differ when they both say [empty string] on the query dump? 当它们在查询转储上都说[空字符串]时,这两个列中的值有何不同?

与两个查询的输出比较

Is it a problem with column names? 列名有问题吗? What kind of data are in those cells? 这些单元格中有哪些数据?

where ( cast('Permit No.' as varchar) <> '' )

The problem is the SQL, not the values. 问题是SQL,而不是值。 By enclosing the column name in quotes, you are actually comparing the literal string "Permit No-.", not the values inside that column. 通过将列名称括在引号中,实际上是在比较文字字符串“ Permit No-。”,而不是该列中的值。 Since the string "Permit No." 由于字符串“许可证号” can never equal an empty string, the comparison always returns true. 永远不能等于空字符串,比较总是返回true。 That is why the resulting query still includes all rows. 这就是为什么结果查询仍然包括所有行的原因。

Unless it was fixed in ColdFusion 2016, QoQ's do not support column names containing invalid characters like spaces. 除非在ColdFusion 2016中已修复,否则QoQ不支持包含无效字符(如空格)的列名称。 One workaround is to use the "columnNames" attribute to specify valid column names when reading the spreadsheet. 一种解决方法是在读取电子表格时使用“ columnNames”属性指定有效的列名称 Failing that, another option is to take advantage of the fact that query columns are arrays and duplicate the data under a valid column name: queryAddColumn(yourQuery, "PermitNo", yourQuery["Permit No."]) (Though the latter option is less ideal because it may require copying the underlying data internally): 失败的话,另一个选择是利用查询列是数组并在有效列名下复制数据的事实: queryAddColumn(yourQuery, "PermitNo", yourQuery["Permit No."]) (尽管后一个选项是不太理想,因为它可能需要在内部复制基础数据):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM