viewpoint-particle

Author Topic: StrCoalesce()  (Read 361 times)

JTaylor

  • Pundit
  • *****
  • Posts: 1085
    • Data & Stuff Inc.
StrCoalesce()
« on: March 28, 2019, 11:29:19 am »
Assuming I haven't overlooked it a StrCoalesce() function would be handy.  Not sure why I hadn't thought to suggest it before but would save a lot of "IF" statements in certain situations.  Thanks.


Jim

td

  • Tech Support
  • *****
  • Posts: 3210
    • WinBatch
Re: StrCoalesce()
« Reply #1 on: March 28, 2019, 01:19:53 pm »
What exactly would we wish this function to do?   For example, in SQL the coalesce function usually returns the first non-null expression in a list in most implementations.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

  • Pundit
  • *****
  • Posts: 1085
    • Data & Stuff Inc.
Re: StrCoalesce()
« Reply #2 on: March 28, 2019, 02:23:26 pm »
Should have been a bit more specific.  Yes.  The same thing.   I process a lot of data, which you have probably figured out by now and working on something now where I have to extract a column and if it is blank then extract another for that value and so on.   Was thinking something like...

   value = StrCoalesce(ItemExtract(12,list,@TAB),ItemExtract(13,list,@TAB),ItemExtract(14,list,@TAB))

would be better than something like:

   value = ItemExtract(12,list,@TAB)
   If value == "" Then value = ItemExtract(13,list,@TAB)
   If value == "" Then value = ItemExtract(14,list,@TAB)


...and Yes, I know I could write a function to do the same.

Thanks.


Jim

td

  • Tech Support
  • *****
  • Posts: 3210
    • WinBatch
Re: StrCoalesce()
« Reply #3 on: March 29, 2019, 07:31:44 am »
I guess that if I were rolling my own, I would implement a UDF with a "for" loop.  Or if speed was critical, use a UDS with "for" loop unrolling optimization if the list was typically long enough to gain from unrolling.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade