Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ValueList with Null Value

Participant ,
Apr 16, 2010 Apr 16, 2010

Hello,

I am outputting values from a query using valueList. If one of the values in the DB is null I get an extra comma in the list. Is there a way for valueList to skip over null values OR is there a better way to make a list like this? Should I be using something like listAppend?

3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 16, 2010 Apr 16, 2010

Modify your query to exclude those records.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 17, 2010 Apr 17, 2010

arrayToList(listToArray(valueList(myQuery.myColumn)))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2010 Apr 18, 2010

BKBK wrote:

arrayToList(listToArray(valueList(myQuery.myColumn)))

I tend to use listChangeDelims() for this, as it seems closer to the intent of the requirement, and is one fewer function calls.  But it amounts to the same thing.

Equally: what Dan suggests should be a consideration.  If you don't want those rows in the first place: don't return them from the DB.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2010 Apr 18, 2010

There is one reason why I consider my suggestion a better strategy. The question the original poster has asked is a local one. My suggestion is a local solution, with no risk of side-effects elsewhere.

Suppose you were to follow the strategy to "change the SQL in the first place to avoid null values" or "change the list delimiter". Then there is a risk that subsequent code that uses the query or the list will crash. In other words, such a change will likely lead to a cascade of further changes down the line.

However, don't get me wrong. I, too, believe a result set to be more  efficient without null values, and one function call to be more  efficient than two.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2010 Apr 18, 2010

You don't need to change the list delimiter, you just use listChangeDelims() to remove the blank entries, eg: listChangeDelims(listWithEmptyItems, ",")

It's leveraging the same technique you are with your list->array->list notion: that CF list functions ignore (and, on the whole: remove) empty list entries.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2010 Apr 18, 2010

Ah, get you.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 20, 2010 Apr 20, 2010

I agree that ommitting the null value from the query would do the job that that isn't always an option. I suppose I could write another query to grab just the values I need from the DB but there is already a query running on the page that returns the data I need. Why hit the DB again if I don't have to?

I'll give these two pieces of code a shot. Thanks guys!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2010 Apr 20, 2010
LATEST

If you need data with empty records anyway, you don't need to go back to the db to filter out the blanks.   You can use Query of Queries.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources