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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:12:10+00:00 2026-06-07T16:12:10+00:00

I am trying to update multiple rows at once (SQL Server 2005). Previously I

  • 0

I am trying to update multiple rows at once (SQL Server 2005). Previously I was updating a single row with this query:

UPDATE dbo.My_Users 
SET MyUserId = @MyUserId
WHERE EmailID = @EmailId

Now @EmailId will have comma-separated EmailIds.

How can I modify the script to update multiple rows? I have seen some examples which make use of UNION ALL. But they are mostly to insert multiple records without where clause.

  • 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-06-07T16:12:12+00:00Added an answer on June 7, 2026 at 4:12 pm

    A similar question was answered in Parameterize an SQL IN clause

    The same idea can be applied here:

    declare @EmailIds varchar = '|email1@test.com|email2@test.com|';
    UPDATE dbo.My_Users SET MyUserId=@MyUserId WHERE @EmailIds LIKE '%|' + EmailID + '|%';
    

    Though this does not contain a comma-separated list, the delimiter could easily be changed to a pipe-character. The caveat here is, the more data that exists in the table and the more email addresses that are in the @EmailIds list, the slower (much slower) this query can become.

    Using C#, I would actually recommend the second example in the above-mentioned question where the list is expanded to create a query similar to:

    UPDATE dbo.My_Users SET MyUserId=@MyUserId WHERE EmailID IN (@email1, @email2);
    

    C# to implement (a modified version of the example in the question above):

    string[] emails = new string { "email1@test.com", "email2@test.com" };
    string sql = "UPDATE dbo.My_Users SET MyUserId=@MyUserId WHERE EmailID IN ({0});"
    string[] emailParams = emails.Select((s, i) => "@email" + i.ToString()).ToArray();
    string inClause = string.Join(",", emailParams);
    using (SqlCommand cmd = new SqlCommand(string.Format(sql, inClause))) {
        for(int i = 0; i < emailParams.Length; i++) {
           cmd.Parameters.AddWithValue(emailParams[i], emails[i]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SQL statement where i'm trying to update multiple rows matching
I'm trying to update multiple columns in a MS SQL statement using a sub-query.
I'm trying to update multiple rows in a table but due to server resources
I'm trying to update multiple rows in one table in MySQL database by doing
I am trying to insert huge multiple rows in a single transaction. But the
I am trying to update multiple rows here.However I fail to point the right
I am trying to update multiple elements at once in a multidimensional array/object and
I am trying to do an SQL query on two tables to retrieve multiple
I am trying to update multiple rows in one table, based on a select
I am trying to update multiple rows on one table using MySQL. I have

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.