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 6897751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:12:33+00:00 2026-05-27T07:12:33+00:00

I have a complex select statement (the union of several queries) which outputs a

  • 0

I have a complex select statement (the union of several queries) which outputs a single column e.g.

| email            |
| test@domain.com  |
| test2@domain.com |
| test3@domain.com |

I would like to feed this into the @blind_copy_recipients of sp_send_dbmail which requires a semi colon (;) separated list.

would normally use COALESCE and a variable to accomplish this but you can’t seem to do that with a statement with UNIONS.

Is there an easy way to do this?

Whilst typing this question is has occurred to me that a better way might be to use a cursor to cycle through the records and send the messages individually but I’m still interested in the answer…..

  • 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. Editorial Team
    Editorial Team
    2026-05-27T07:12:34+00:00Added an answer on May 27, 2026 at 7:12 am

    Avoid cursors as much as possible.

    In the meantime, try this:

    DECLARE @blind_copy_recipients VARCHAR(4000) 
    -- Or whatever is the suitable size you expect
    
    SELECT @blind_copy_recipients = COALESCE(@blind_copy_recipients + ', ', '') + 
       CAST(BCC.BLIND_COPY_RECIPIENTS_UNION_OUTPUT_COLUMN AS VARCHAR(50)) 
        -- Again, change to suit your needs
    FROM 
    (
    -- SELECT UNION SELECT UNION SELECT UNION --
    ) AS BCC
    
    SELECT @blind_copy_recipients
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively complex query, with several self joins, which works on a
Using a stored procedure i have a fairly complex SQL statement which returns a
I have a stored proc that performs a fairly complex SELECT statement. The stored
I have a rather complex SELECT statement in a stored procedure that I am
I have a complex MySQL problem. SELECT * FROM banners, content_id_country, languages WHERE content_id_country.content_id
I am using WCF and REST, and I have complex types, which are working
I have a complex WPF UserControl made of other ContentControl templates which contain sets
I have a select from (nothing to complex) Select * from VIEW This view
I have optimized a complex Oracle statement using temporary table like this : original
Here is my problem. I have a select statement something like this: select *

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.