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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:53:51+00:00 2026-06-08T17:53:51+00:00

I am working on a stored procedure to get accounts for a case. If

  • 0

I am working on a stored procedure to get accounts for a case. If the @accounts parameter is NULL, I want to get all the accounts for the case. If @accounts is NOT NULL, then it will be a comma separated string of accountid’s. I would like to have a single where clause that can handle this. Something that says if @accounts is NULL then grab all the accounts for the case. Otherwise, use the @accounts parameter and grab the accounts with the account id’s specified. I would like to avoid a big IF statement that would require me to have the query twice with 2 different WHERE clauses.

DECLARE @caseId BIGINT,
    DECLARE @accounts VARCHAR(255)

    SELECT TOP 1 @userId = userId FROM TblTraceCur t
    WHERE caseId = @caseid
    ORDER BY processDate DESC

    SELECT    
              .... (select logic) ...
    WHERE     
              t.caseId = @caseID AND 
              t.userId = @userId AND
              t.shortStock = 0 AND
              ... (where I need the new logic) ...
    order by t.tracln ASC

Thanks a lot!

  • 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-08T17:53:52+00:00Added an answer on June 8, 2026 at 5:53 pm

    This worked for me. Add (@accounts IS NULL OR @accounts LIKE ('%,' + CAST(t.caseId AS VARCHAR(255)) + ',%')) where you indicated in your post. Of course you have to make sure that your first character and last character in @accounts are commas for this to work but it’s the easiest I think. Not having the commas would return ids falsely for example: having @accounts = 12 would return ids 1, 2, and 12. Using commas and making sure they’re the first and last characters prevent this from happening.

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

Sidebar

Related Questions

When I try to execute the stored procedure in ColdFusion, then not all of
I've been working on a Stored Procedure that checks the time, then retrieves records
I want to do following: Make Oracle stored procedure for read all data from
I wrote a simple Stored Procedure with a while loop that's not working. Here's
I am working on a stored procedure that will trigger once a week so
There are databases on Firebird and SQL Server. I have working stored procedure in
I've been working on a stored procedure that runs a select statement in a
Can someone provide a working example in which stored procedure returns a recordset and
I'm working on a pl sql stored procedure. What I need is to do
I have a stored procedure that has been working just fine, but I recently

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.