Link to home
Start Free TrialLog in
Avatar of LeighWardle
LeighWardleFlag for Australia

asked on

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:

User generated image
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
Avatar of als315
als315
Flag of Russian Federation image

Can you show exact expected result?
Should it be csv file?
Avatar of LeighWardle

ASKER

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

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
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

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
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

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
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

ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many thanks, als315.
You are a Legend!
Regards,
Leigh