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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:17:27+00:00 2026-05-27T04:17:27+00:00

I have a Stored Proc query below which involves returning partial delimited search string.

  • 0

I have a Stored Proc query below which involves returning partial delimited search string. E.g.searching passing a search string of ‘wis,k’ will return all results with ID that has ‘wis’ and ‘k’ in them. I am using a function and a cross join for this but the problem if attaching the cross join will prevent loading all my data which I will need to when I load this SPROC. I was thinking if a conditioned Cross Join is possible such that when my search string variable ‘@ReceiptNo’ is null then I will omit the Cross Join and allow all my data to be displayed. Please kindly advice. Thanks.

Portion of my SPROC:

    FROM [Transact] T 
    LEFT JOIN [Outlet] O On (T.Outlet_Code = O.Code)
    LEFT JOIN [SystemCode] SC on (CONVERT(NVARCHAR,T.Mode) = SC.Code)
    CROSS JOIN DBO.SPLIT(@ReceiptNo , ',') --SPLIT function to seperate delimited string
    Where
    (
       CardNo In
       (
          Select [CardNo]
          FROM [Card]
          WHERE [CardNo] = @CardNo
             AND [DeletedBy] IS NULL
             AND [DeletedOn] IS NULL
             AND [MemberID] = @MemberId
       )
    )
       and
       (
          (T.TransactDate Between @TransactDateFrom And @TransactDateTo
             or @TransactDateFrom is null
             or @TransactDateTo is null
          )
          and (T.TransactDate >= @TransactDateFrom
             or @TransactDateFrom is null)
          and (T.TransactDate <= @TransactDateTo
             or @TransactDateTo is null)             
          and
          (
             (',' + @Mode +',' LIKE '%,' + CONVERT(VARCHAR, T.Mode) + ',%')
             or @Mode is null
          )
         and    (T.ReceiptNo LIKE '%' + VAL + '%')  --This is the 'LIKE' condition to return desired search string results
          or (@TransactDateFrom is null
             and @TransactDateTo is null 
             and @Mode is null 
             and @Outlet_Code is null
             and @ReceiptNo is null
             )
       )
    Group by T.AutoID, TransactDate,TransactTime, SC.Name, O.Name
       , ReceiptNo, AmountSpent, TransactPoints, VoidOn
  • 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-05-27T04:17:28+00:00Added an answer on May 27, 2026 at 4:17 am

    You need to take care of NULL and set it to any constant value. Modify CROSS JOIN to (read notes below query):

    CROSS JOIN (SELECT ISNULL(Portion, 1) AS Portion FROM DBO.SPLIT(@ReceiptNo , ',')) TTT
    

    In query above, Portion is column returned by DBO.SPLIT function. Change its name to appropriate and add more columns (with ISNULL) if needed.

    Am I missing something or You can simply use LEFT JOIN instead of CROSS JOIN? Also, You might consider putting DBO.SPLIT function result into temporary table, index it and then use it in your CROSS/LEFT JOIN.

    EDIT#1: I can’t find any reason why You should not change CROSS JOIN to LEFT JOIN, as it will process less rows when @RecepitNo is not NULL.

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

Sidebar

Related Questions

I have a Stored Proc which performs search on records. The problem is that
I have a SQL Insert query inside a stored proc, for inserting rows into
I have a Stored proc which returns 6 select statement results. I'm trying to
I am using SQL 2000. I have a stored proc, spGetApplicantList , which cannot
I have the code below to query records from a stored procedure but am
I have a stored proc that does a geospatial query. The proc issues two
I have a stored proc mapped as follows in NHibernate: <sql-query name=HistoricSearch> <return class=ResultItem>
I have a stored proc that I am passing two parameters into. One parameter
Using SQL Server 2008. I have a stored proc which has start and end
I have a sql query (stored proc) that takes about 8-10seconds to return before

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.