Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 164307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:43:15+00:00 2026-05-11T11:43:15+00:00

I have a string of email recipients in the format like this: DECLARE @recipients

  • 0

I have a string of email recipients in the format like this:

 DECLARE @recipients VARCHAR(MAX);  ....  PRINT @recipients;  /* the result  person1@yahoo.com;person2@hotmail.com;person1@yahoo.com;...  */ 

‘SELECT DISTIECT …’ is a simple and powerful SQL statement, but it works against a table. Is there a simple way to select distinct recipient from the recipient list variable like FOR loop in C# or Ruby?

 FOR @recipient IN @recipients  BEGIN     -- send email to @recipient  END 

By the way, I am using TSQL in SQL server 2005.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:43:16+00:00Added an answer on May 11, 2026 at 11:43 am

    Here’s a solution for you that uses a temporary table.

    declare @emails varchar(2000) set @emails = 'person1@yahoo.com;person2@hotmail.com;person1@yahoo.com;'  declare @results table (row int identity(1,1), email varchar(500))  while ((select charindex(';',@emails)) > 0) begin        insert into @results select substring(@emails,1,charindex(';',@emails))     select @emails = substring(@emails,charindex(';',@emails)+1,len(@emails)) end  select distinct email from @results 

    The idea is to continously parse the email from the string, insert it into a temporary table, and remove the parsed email from the remaining string.

    You can use loop through the temporary table afterward to send your individual emails.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following String First Last <first.last@email.com> I would like to extract first.last
I have some java classes like, Class User { String email; String name; String
I have the following: public class Address { public string Email { get; set;
I have two models: User (email:string) Profile (name:string) class User < ActiveRecord::Base has_one :profile
I have following syntax in my script to get email address from string. The
i have this error when i sending email through our web application Mailbox unavailable.
I have a string that could have email address in two different ways way
I have a Report object that has Recipients property (of String datatype). The Recipients
I have in invitation_mailer.rb the next: class InvitationMailer < ActionMailer::Base default :from => email@email.com
I have a method: private List<String> userCns = Collections.synchronizedList(new ArrayList<String>()); private List<String> recipients =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.