I have table which holds contact information on clients. The table holds email addresses and other personal data, plus 300 a 400 columns with list names where the contact is either subscribed, unsubscribed or null (so not in that list at all). For each list (column name) I have an additional column holding a date ( of subscribing or unsubscribing)
It is very hard to handle this list.
Now I am trying to make a query which gives me all the mail addresses, with the names of the column where the field is not null. In that way I can see which client is in which list. I wanted to do it dynamically ( I have different lists with different number of columns so I can reuse the code)
I have been trying it with Case ( not so dynamic), but is takes a long way of coding.
I know that there ar other similar questions, but I don't quite understand the answers. This is also my first question here, suggestions to improve are always welcome.
Many thanks in advance.Example of the code should be like:
SELECT test.email,
(
CASE
WHEN Test.Column_Status <>'0'
THEN Columname
ELSE 0
END
)
FROM test
GROUP BY test.email