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

  • Home
  • SEARCH
  • 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 8609857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:58:48+00:00 2026-06-12T03:58:48+00:00

First I apologize for the poor formatting here. Second I should say up front

  • 0

First I apologize for the poor formatting here.

Second I should say up front that changing the table schema is not an option.

So I have a table defined as follows:

Pin varchar
OfferCode varchar

Pin will contain data such as:
abc,
abc123

OfferCode will contain data such as:
123
123~124~125

I need a query to check for a count of a Pin/OfferCode combination and when I say OfferCode, I mean an individual item delimited by the tilde.

For example if there is one row that looks like abc, 123 and another that looks like abc,123~124, and I search for a count of Pin=abc,OfferCode=123 I wand to get a count = 2.

Obviously I can do a similar query to this:
SELECT count(1) from MyTable (nolock) where OfferCode like '%' + @OfferCode + '%' and Pin = @Pin

using like here is very expensive and I’m hoping there may be a more efficient way.

I’m also looking into using a split string solution. I have a Table-valued function SplitString(string,delim) that will return table OutParam, but I’m not quite sure how to apply this to a table column vs a string. Would this even be worth wile pursuing? It seems like it would be much more expensive, but I’m unable to get a working solution to compare to the like solution.

  • 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-12T03:58:49+00:00Added an answer on June 12, 2026 at 3:58 am

    Your like/% solution is open to a bug if you had offer codes other than 3 digits (if there was offer code 123 and 1234, searching for like ‘%123%’ would return both, which is wrong). You can use your string function this way:

    SELECT Pin, count(1) 
    FROM MyTable (nolock) 
    CROSS APPLY SplitString(OfferCode,'~') OutParam 
    WHERE OutParam.Value = @OfferCode and Pin = @Pin
    GROUP BY Pin
    

    If you have a relatively small table you can probably get away with this. If you are working with a large number of rows or encountering performance problems, it would be more effective to normalize it as RedFilter suggested.

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

Sidebar

Related Questions

I first apologize for my poor english level and maybe for the stupidity of
First, I apologize for my poor English. I am trying to build a list
First of all, i want to apologize for my poor English for it is
I apologize for making my first question not the hard-hitting code-related question I was
First, I apologize if this is not an appropriate venue to ask this question,
First off I apologize if there is another post out there that answers this,
First of all - I apologize if this question shows ignorance or I'm not
First, let me apologize, I'm new at web development, so I'm not quite sure
First, I apologize. I know what I want to do, but not what I
At first I want to apologize for my poor english. Is there any way

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.