Skip to content
Advertisement

Apply multiple validation to SQL records and identify all failing validations

I have a requirement where I need to capture all failing validations in SQL database.

I have below table:

My validation rules are as follows:

  1. Department should be IT
  2. Age should be in 20s
  3. Age should not be 25

These are sample validation and my requirement is to capture all failed records along with failing conditions, I have achieved it by using union as follows:

Below is the result achieved:

But, if the validations increase I have to add many select query.

Is there any alternative way with better performance?

Advertisement

Answer

You could use cross apply:

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