Skip to content
Advertisement

SQL loop through columns with name to find max date

I’m looking for the SQL to loop through 20 columns with dates, to find the max.

My code is kind of bad now:

it’s oracle database, i konow that max date is in filed annex_20

Advertisement

Answer

First of all, you don’t need ANNEX_XX_DATE is not null since ANNEX_XX_DATE<>... can’t be true if ANNEX_XX_DATE is null, so you can make it easier without it:

Also I would probably replace it with coalesce(nullif(…)…) to make it easier and shorter:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement