SELECT id
FROM tickets
WHERE id IS NOT NULL
AND (
passenger_name IS NULL
OR contact_data IS NULL
OR seat_no IS NULL
OR travel_date IS NULL
OR flight_id IS NULL
);
DECLARE @sql NVARCHAR(MAX) = '';
DECLARE @tableName NVARCHAR(MAX) = 'tickets';
SELECT @sql = CONCAT(@sql,
' OR ',
QUOTENAME(column_name),
' IS NULL')
FROM information_schema.columns
WHERE table_name = @tableName;
SET @sql = CONCAT('SELECT id FROM ', @tableName, ' WHERE ', STUFF(@sql, 1, 4, ''));
EXEC sp_executesql @sql;
Обратите внимание на группировку условий.