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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:11:14+00:00 2026-06-03T19:11:14+00:00

I have a function that takes two delimited strings and returns the number of

  • 0

I have a function that takes two delimited strings and returns the number of common elements. The

The main code of the function is (@intCount is the expected return value)

    SET @commonCount = (select count(*) from (
    select token from dbo.splitString(@userKeywords, ';')
    intersect
    select token from dbo.splitString(@itemKeywords, ';')) as total)

where splitString uses a while loop and charIndex to split a string into delimited tokens and inserts it into a table.

The problem I am having is that this only processes at a speed of about 100 rows per second and by the size of my dataset, this will take about 8-10 days to finish.

The size of the two strings may be upto 1500 characters in length.

Is there anyway I can achieve this fast enough to be usable?

  • 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-03T19:11:16+00:00Added an answer on June 3, 2026 at 7:11 pm

    The performance problem is probably the combination of a cursor (for the while loop) and the user defined function.

    If one of these strings is constant (such as item key words), you can search for each one independently:

    select *
    from users u
    where charindex(';'+<item1>+';', ';'+u.keywords) > 0
    union all
    select *
    from users u
    where charindex(';'+<item2>+';', ';'+u.keywords) > 0 union all
    

    Alternatively, a set based approach can work, but you have to normalize the data (plug here for having data in the right format to begin with). That is, you want a table that has:

    userid
    keyword
    

    And another that has

    itemid
    keyword
    

    (if there are different types of items. Otherwise this is just a list of keywords.)

    Then your query would look like:

    select *
    from userkeyword uk join
         itemkeyword ik
         on uk.keyword = ik.keyword
    

    And the SQL engine would perform its magic.

    Now, how can you create such a list? If you have only a handful of key words per user, then you can do something like:

    with keyword1 as (select u.*, charindex(';', keywords) as pos1,
                             left(keywords, charindex(';', keywords)-1) as keyword1
                      from user u
                      where charindex(';', keywords) > 0
                     ),
         keyword2 as (select u.*, charindex(';', keywords, pos1+1) as pos2,
                             left(keywords, charindex(';', keywords)-1, pos1+1) as keyword2
                      from user u
                      where charindex(';', keywords, pos1+2) > 0
                     ),
            ...
    select userid, keyword1
    from keyword1
    union all
    select userid, keyword2
    from keyword2
    ...
    

    To get the maximum number of elements in the itemKeyWords, you can use the following query:

    select max(len(Keywords) - len(replace(Keywords, ';', '')))
    from user
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have need for a function pointer that takes two arguments and returns a
I have a function that takes a floating point number and returns a floating
I have a function that takes in two strings, and I want to, let's
I have a function that currently takes in two template parameters. One is expected
I have to write a library which contains a function that takes two strings
I have written a function that takes two arguments and returns a SETOF result.
I have a function that takes two arguments, the first one $methodName being a
I have a simple javascript function that takes two variables. I need to pass
I have a function f that takes two parameters ( p1 and p2 ):
I need to run a function that takes two arguments several times. 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.