CoolStraw
CoolStraw

Reputation: 5390

Query Transform and Pivot

I have a very subtle problem and I'm unable to solve it until now. Let's take an example to better explain the problem:

I have a table Person: With fields: ID, Name, Option1, Option1_Value, Option2, Option2_Value, Option3, Option3_Value

I want a query that shows the following:

ID      Name      Reason
1       Clark     Option1 doesn't match, Option2 doesn't match
2       Stefan    Option3 doesn't match
3       Sandra    (No errors: well just ignore this line)
4       Steven    Option2 doesn't match

So what has to be done is: for every option field, do a check (a query that's going to read and compare the option_value using an external table) and then print the options that doesn't match but in ONE field that serves as an error output field.

Is it possible to achieve this using Transform and Pivot ? If so, could you please provide me with tips and advise on how should I use them ? If not, is there an alternative ? Or maybe something I can do VBA-side ?

Thank you in advance guys Miloud

Upvotes: 0

Views: 290

Answers (1)

Fionnuala
Fionnuala

Reputation: 91376

Your table already has the three options in a row, so how about:

SELECT ID, Name, 
     IIf(Option1_Value<>"Something","Option1 dosn't match",
        IIf (Option2_Value<>"Something","Option2 dosn't match",
           IIf( Option3_Value<>"Something","Option3 dosn't match","No errors")))
     As Reason
FROM Table

It is not quite clear from your post what the options do not match, nor is it clear what is the difference between Option and Option_Value.

Upvotes: 1

Related Questions