I had a table of 10 K records and 10 columns. Most of the records had NULL values in one or two columns. They may be any column as in below screenshot. I needed to filter all records for which at least one value is filled.
So initially I thought of writing query as below.
So initially I thought of writing query as below.
SELECT * FROM ItemDetails WHERE
[Desc] IS NOT NULL OR Color IS NOT NULL OR
Size IS NOT NULL OR Shape IS NOT NULL OR plasticfree IS NOT NULL
I found an query which is more easier using COALESCE function which results same as above query.[Desc] IS NOT NULL OR Color IS NOT NULL OR
Size IS NOT NULL OR Shape IS NOT NULL OR plasticfree IS NOT NULL
SELECT * FROM ItemDetails WHERE COALESCE([Desc],Color,Size,Shape,plasticfree) IS NOT NULL
No comments:
Post a Comment