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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:38:33+00:00 2026-06-13T03:38:33+00:00

There are two strings a and b The a string contains comma. I would

  • 0

There are two strings a and b

The a string contains comma. I would like to split the a string by comma, then go through every element .

IF the b string contains any element which split by comma will return 0

(e.g: a = "4,6,8" ; b = "R3799514" because the b string contains 4 so return 0)

How to achieve this with a stored procedure? Thanks in advance!

I have seen a split 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(@slice)     

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

select top 10 * from dbo.split('Chennai,Bangalore,Mumbai',',')
  • 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-13T03:38:34+00:00Added an answer on June 13, 2026 at 3:38 am

    Following will work –

    DECLARE @A VARCHAR (100)= '4,5,6'
    DECLARE @B VARCHAR (100)= 'RXXXXXX'
    DECLARE @RETURN_VALUE BIT = 1 --DEFAULT 1
    
    
    SELECT items
    INTO #STRINGS 
    FROM dbo.split(@A,',')
    
    IF EXISTS(SELECT 1 FROM #STRINGS S WHERE CHARINDEX(items, @B) > 0)
    SET @RETURN_VALUE = 0
    
    PRINT @RETURN_VALUE
    
    DROP TABLE #STRINGS
    

    You can also use CONTAINS instead of CHARINDEX –

    IF EXISTS(SELECT 1 FROM #STRINGS S WHERE CONTAINS(items, @B))
    SET @RETURN_VALUE = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two strings. String str1=Order Number Order Time Trade Number; String str2=Order Tm;
There is supposed to be a comma between these two strings foo = ['dumb'
The problem it's easy. Is there any function in JAVA to compare two Strings
Possible Duplicate: Concatenate Two NSDate String values Just confused that is there any default
I wonder if there is a way of concating two strings in Silverlight inside
I am wondering if there's an easy way to detect phrases in two strings
There are two lists: List<string> excluded = new List<string>() { .pdf, .jpg }; List<string>
Let's say I have two same strings inside an ArrayList... is there a way
Is there a PHP function that grabs the string in between two characters. For
I wrote two methods to check there performance public class Test1 { private String

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.