Written by

System developer at Region Örebro län
Question Michael Lundberg · Dec 20, 2023

How to select ID from table based on a value in a List?

Hello!

I wonder how to select a conditional value from a Table column that has lists of values?
Example: I have a table in the database that looks like below:

ID Itemname IDList
1 TestItem 1 7 10 17

For example, I want to know which Itemname it is for number 10 that is in the IDList. What should this SQL syntax look like? I have tried %INLIST and other things but only get blank value. How should the SQL-syntax for that query look like?

Greatful for all tips.
Regards,
Michael

Product version: IRIS 2023.1
$ZV: IRIS for Windows (x86-64) 2023.1.1 (Build 380U) Fri Jul 7 2023 23:43:12 EDT [HealthConnect:5.1.0-1.m1]

Comments

David Hockenbroch · Dec 20, 2023

If your IDList is a string, you'd have to use WHERE 10 %INLIST $LISTFROMSTRING(IDList,' ') so that the string is converted to an actual list for %INLIST to work.

0
Michael Lundberg  Dec 20, 2023 to David Hockenbroch

Hi David!

It's integers-values in the list. It's actually IDs from other tables

/Michael

0
Michael Lundberg  Dec 21, 2023 to Enrico Parisi

Hello Enrico

Thanks! It worked.


SELECT Item Name
from <Table>
WHERE FOR SOME %ELEMENT(IDList) (%VALUE=10)
cooked the steak! :0)

Regards,
Michael

0