We help IT Professionals succeed at work.
Get Started

SQL search for a value contained within a parameter

woodwyn
woodwyn asked
on
240 Views
Last Modified: 2012-05-12
We are creating an interface with multiple checkboxes for categories (Category designation samples: L1,L2,C1,etc).  We will use this interface in multiple environments, each with unique category designations.  I want to create a stored procedure I can use in all environments that will accept a list of the checked category designations, seperated perhaps with a semi-colon, in one character string ('L1;C2;P3'), parse out the category designations and then only include results for those categories.  What is the best way to do this?

CREATE PROCEDURE [GetItems]
@cCategoryCodes char(100)  -- Codes will be seperated by a semi-colon
SELECT
   Items.Number,
   Items.Description,
   ItemCode = (SELECT ItemCategories.Code FROM ItemCategories WHERE ItemCategories.keyItemCategories = Items.keyItemCategories)

FROM Items
WHERE ItemCode IN @cCategoryCodes
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE