Special SQL to export customer data to MailChimp

Hi Experts,

I am attempting to export customer data from MS Access to MailChimp.
My MailChimp List uses a Group called "Interests".
So a customer can nominate 0-4 interests: Interest1, Interest2, Interest3, Interest4.

I have a Crosstab query that outputs the customer interests in this form:

Sample output from Crosstab query
The complication is that MailChimp rolls Interests in to a single field, for example:

"Interest1, Interest2, Interest3, Interest4" - if customer is interested in all 4 topics
"Interest1, Interest4" - if customer is interested in these 2 topics
"" - if customer has not specified any interests

Is it possible to generate this type of output using SQL?

Here is a sample MS Access database for testing.

Regards,
Leigh
LVL 1
LeighWardleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

als315Commented:
Can you show exact expected result?
Should it be csv file?
0
LeighWardleAuthor Commented:
Yes, I want to generate a csv file. something like this:

"Email Address","First Name","Last Name","Interests" 
x.y@domain.com,John,Doe,"Interest1, Interest4"
.........

Open in new window

0
als315Commented:
Can you show corect csv data from your sample?
ClientID,Interest1,Interst2,Interest3,Interest4
1,,,,
10110103,,2,,
10110104,,2,1,
10110105,,2,,
...
10110109,1,2,,
10110110,,3,1,1
or
1
10110103,2
10110104,2,1
10110105,2
...
10110109,1,2
10110110,3,1,1
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LeighWardleAuthor Commented:
Here is the correct csv data from my sample:

"ClientID","<>","Interest1","Interest2","Interest3","Interest4"
"1",1,,,,
"10110103",,,2,,
"10110104",,,2,1,
"10110105",,,2,,
"10110106",,,2,1,
"10110108",,,2,1,
"10110109",,1,2,,
"10110110",,,3,1,1

Open in new window

0
als315Commented:
Change your query to:
TRANSFORM Count(CLIENTS3.ClientID) AS CountOfClientID
SELECT CLIENTS3.ClientID
FROM CLIENTS3 LEFT JOIN ([Item Transactions] LEFT JOIN Items ON [Item Transactions].ItemID = Items.ItemID) ON CLIENTS3.ClientID = [Item Transactions].CustomerID
GROUP BY CLIENTS3.ClientID
PIVOT IIf(IsNull([ItemCategory]),"<>",[ItemCategory]);

Open in new window

and export it as text with master. Don't forget to incliude headings into export.
Result is included
aaa-MailChimp-Export---Crosstab.txt
0
LeighWardleAuthor Commented:
Thanks, als315.

As I commented above, the csv file output that I need is something like this:

"Email Address","First Name","Last Name","Interests" 
x.y@domain.com,John,Doe,"Interest1, Interest4"
.........

Open in new window

0
als315Commented:
In your comment #a40778226 I see sample. Output from my query is exactly as in this comment.
If your comment was wrong, please, show exact expected csv file, based on your sample DB
0
LeighWardleAuthor Commented:
Hi als315, please accept my apologies for our misunderstanding.

The exact expected csv file, based on my sample DB is:

ClientID	Interests
1	
10110103	Interest2
10110104	"Interest2,Interest3"
10110105	Interest2
10110106	"Interest2,Interest3"
10110108	"Interest2,Interest3"
10110109	"Interest1,Interest2"
10110110	"Interest2,Interest3"

Open in new window


It would not matter if quotes are included, for example:

ClientID	Interests
1	                ""
10110103	"Interest2"
..........

Open in new window

0
als315Commented:
You can use DConcat function from Patrick Mattews article Domain Aggregate for Concatenating Values
In sample this function is added to Module1. In the beginning of function you can find description of fields.
Final query - "MailChimp Export"
Crosstab-Query-Test.accdb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Many thanks, als315.
You are a Legend!
Regards,
Leigh
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.