Skip to content

SQL Query – 1 Column to 1 Record

June 3, 2009

I run into this somewhat frequently, and the answer is relatively simple… but every time I run into it, I start by searching for the fix… putting this here for my own benefit as much as anyone elses’.

If you have ever had a ‘Users’ table with an ‘Email’ column and wanted to send an email to all those users, this query will get you what you need:

SELECT @EmailAddresses = COALESCE(@EmailAddresses +’;’,”) + Email FROM Users
SELECT @EmailAddresses

This will spit out a string that can be pasted into Outlook or any other email program that separates multiple recipients by semi-colon and will work.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: