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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:31:32+00:00 2026-06-10T04:31:32+00:00

I want to insert multiple email into SQL Server table cell and before inserting

  • 0

I want to insert multiple email into SQL Server table cell and before inserting them I need check whether the values are already there or not.

For more clarification

Row_id        EMAIL_ID
  1           abc@xyz.com,abcabc@xyz.com, abc2@xyz.com
  2           pqr@xyz.com,pqrabc@xyz.com

Now If I insert abcabc@xyz.com,free@xyz.com, it will show that value is duplicated.

I did this

select EMAIL_ID
from TR_DEMO
INNER JOIN dbo.split('abcabc@xyz.com,free@xyz.com', ',') s
ON s.items IN (select items from dbo.split(EMAIL_ID, ',') )

Function

CREATE FUNCTION [dbo].[Split]
(
    @String varchar(8000), 
    @Delimiter char(1)
)       
returns @temptable TABLE (items varchar(8000))       
as       
begin       
    declare @idx int       
    declare @slice varchar(8000)       

    select @idx = 1       
        if len(@String)<1 or @String is null  return       

    while @idx!= 0       
    begin       
        set @idx = charindex(@Delimiter,@String)       
        if @idx!=0       
            set @slice = left(@String,@idx - 1)       
        else       
            set @slice = @String       

        if(len(@slice)>0)  
            insert into @temptable(Items) values(rtrim(ltrim(@slice)))       

        set @String = right(@String,len(@String) - @idx)       
        if len(@String) = 0 break       
    end   
return       
end 

It works fine, but query is slow while checking the records around 100000

Can we do the same by wildcard or something else?

  • 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-10T04:31:33+00:00Added an answer on June 10, 2026 at 4:31 am

    There is a trick you can use for comparing against a comma-separated list. First, you’ll want to split your input list. Then for each item, you’ll want to check the following:

    SELECT EMAIL_ID
      FROM TR_DEMO
     WHERE ','+EMAIL_ID+',' LIKE '%,abcabc@xyz.com,%'
    

    Demo: http://www.sqlfiddle.com/#!3/6dd71/2

    Here’s another example using your SPLIT method to generate the items:

        SELECT EMAIL_ID
          FROM TR_DEMO T
    INNER JOIN dbo.split('abcabc@xyz.com,free@xyz.com', ',') s
                   ON ','+T.EMAIL_ID+',' LIKE '%,'+s.items+',%'
    

    http://www.sqlfiddle.com/#!3/a9a7b/1

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

Sidebar

Related Questions

I want to batch insert multiple records in sql server database using ADO.NET command/sqldataadapter
I want to insert multiple rows into a DB2 table. I have a query
I want to insert some data into a table and I want the multiple
I have multiple string values, I want to insert in an sql server db
I want to insert a record into a MySQL database table from a formulaire.
I want to insert widgets into my ItemsControl and make them resizeable. How do
I have a SQL query where I want to insert multiple rows in single
I have a source piece of xml into which I want to insert multiple
For SQL Server 2005, if I want to insert about 20 or 30 rows
I want to insert a 2 dimensional array into a DB table. Is there

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.