2

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.

Using CF16 server

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. How do the values in both those columns differ when they both say [empty string] on the query dump?

output comparison with both query of queries

Is it a problem with column names? What kind of data are in those cells?

10
  • Any difference if you try where col is NOT NULL? What kind of data are in those cells Dump it and find out. Something like writeDump(yourQuery.columnName[rowNum].getClass().name). Might also check the value lengths to see if it really is an empty string. Commented Aug 9, 2016 at 16:58
  • @Leigh java.lang.String in a cell like 23 with [empty string]. is not null check didn't change anything. Thanks for pointing out the getClass function Commented Aug 9, 2016 at 17:05
  • (Edit) Aside from verifying the value length is actually 0, are you sure the SQL is valid? Reason for asking is I do not recall if that is the correct way to escape invalid column names in a QoQ, off the top of my head. Commented Aug 9, 2016 at 17:19
  • @Leigh I tried doing a CHARACTER_LENGTH, CHAR_LENGTH, LENGTH, and LEN check on ('Permit No.') > 1 but those gave me an error on the syntax? And even when I do the selection on 'Contractor' it gives me the empty ones. City is also java.lang.String. Should I rename columns first? Rebuild the query? Commented Aug 9, 2016 at 17:26
  • Edit: You cannot use a QoQ (very little function support). Use the LEN function on a single value ie LEN( queryName["colName"][rowNum] ). BTW, did you see my question about syntax? Commented Aug 9, 2016 at 17:41

1 Answer 1

3

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

The problem is the SQL, not the values. By enclosing the column name in quotes, you are actually comparing the literal string "P-e-r-m-i-t N-o-.", not the values inside that column. Since the string "Permit No." can never equal an empty string, the comparison always returns 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. One workaround is to use the "columnNames" attribute to specify valid column names when reading the spreadsheet. 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):

Sign up to request clarification or add additional context in comments.

2 Comments

I ended up renaming the columns and the query worked much better and gave 80 rows rather than 42,000.
Good to hear. Sounds like restricting the "columns" returned in the query had the added benefit of excluding the extras, which happened to contain all those "empty" cells ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.