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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:44:36+00:00 2026-06-10T06:44:36+00:00

I am having following stored procedure in my SQL Server 2008 R2 database ALTER

  • 0

I am having following stored procedure in my SQL Server 2008 R2 database

ALTER PROCEDURE [dbo].[usp_send_email] 
    @pStatus Int Out,
    @pEMailId Int Out,
    @pSenderUserName varchar(MAX),  
    @pReceivers VarChar(50),         **-- this column can have csv values**
    @pSub NVarChar(100),
    @pCon NVarchar(MAX),
    @pHasAttachments Bit
AS
BEGIN
   --SET NOCOUNT ON;

   Insert Into MessagingMessage
      (
       CreatedBy,
       [Subject],
       Body,
       HasAttachments
      )
     Values
     (    
      @pSenderUserName,
      @pSub,
      @pCon,
      @pHasAttachments
      )
    SET @pEMailId = SCOPE_IDENTITY()  

     Insert Into MessagingMessageReceipient
      (
       MessageId,
       ReceipientId,
       ReceipientType
      )
     Values
     (    
      @pEMailId,
      @pReceivers,
      1
      )
     SET @pStatus  = SCOPE_IDENTITY() 

END

In above code I want to run the first statement only one time but second insert statements in loop for each comma separated username.CSV value coming as a parameter is already validated by C# code so no need to validate it.

  • 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-10T06:44:38+00:00Added an answer on June 10, 2026 at 6:44 am

    Using this link: how to split and insert CSV data into a new table in single statement?, there is a function you can use to parse csv to to table and I have used it in the code below. Try the following

    Insert Into MessagingMessageReceipient
      (
       MessageId,
       ReceipientId,
       ReceipientType
      )
      SELECT
       @pEMailId,
       csv.Part,   -- each @pReceiver
       1
      FROM 
         dbo.inline_split_me(',',@pReceivers) csv
    

    And the function is copied below

    CREATE FUNCTION inline_split_me (@SplitOn char(1),@String varchar(7998))
    RETURNS TABLE AS
    RETURN (WITH SplitSting AS
               (SELECT
                    LEFT(@String,CHARINDEX(@SplitOn,@String)-1) AS Part
                        ,RIGHT(@String,LEN(@String)-CHARINDEX(@SplitOn,@String)) AS Remainder
                    WHERE @String IS NOT NULL AND CHARINDEX(@SplitOn,@String)>0
                UNION ALL
                SELECT
                    LEFT(Remainder,CHARINDEX(@SplitOn,Remainder)-1)
                        ,RIGHT(Remainder,LEN(Remainder)-CHARINDEX(@SplitOn,Remainder))
                    FROM SplitSting
                    WHERE Remainder IS NOT NULL AND CHARINDEX(@SplitOn,Remainder)>0
                UNION ALL
                SELECT
                    Remainder,null
                    FROM SplitSting
                    WHERE Remainder IS NOT NULL AND CHARINDEX(@SplitOn,Remainder)=0
               )
               SELECT Part FROM SplitSting
           )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having difficulty executing a MS SQL Server stored procedure from Java/jsp. I
I am having a very weird problem with building a SQL Server 2008 Database
i m having following type of simple sql server table Here I want to
Is there a way to write SQL Server Stored Procedure which to be strongly
I am having trouble returning data from my sql-server database to an aspx page
Can't find the solution. I'm having the following stored procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_process_upload_log`(
I am having trouble calling the following stored procedure. When I call ExecuteReader, I
I am having following normal query inside my stored procedure Select DISTINCT UI.UserId,UI.UserName, UI.FullName
I have a Products table in a SQL Server database and I am having
I'm having trouble getting the following to work in SQL Server 2k, but it

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.