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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:28:13+00:00 2026-05-29T12:28:13+00:00

I have a large number of stored procedures that basically do the same thing:

  • 0

I have a large number of stored procedures that basically do the same thing: get a list of values as parameters, then go to some table and SELECT all the rows WHERE these values match.

I would like to be able to have a single stored procedure that would be able to handle all these cases.

How would you tackle this?

  • 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-29T12:28:14+00:00Added an answer on May 29, 2026 at 12:28 pm

    You can try to use XML based approach for your problem. Send an XML as an input parameter. Convert the xml into a table. From the table form dynamic query and execute it in order to achieve your desired functionality. See the below example. In this example Departments is a table which contains 3 columns pkDepartmentId (int), DepartmentName (varchar) and BuildingNumber (int). Using this approach you can send n Number of parameters and their values as input parameters.

    pkDepartmentId DepartmentName BuildingNumber
    1 Electronics and Communication 1
    2 Computer Science 2
    3 Instrumentation and Technology 4

    --EXEC TestProc '<Parameters>
    --                  <Param>
    --                      <ColumnName>pkDepartmentId</ColumnName>
    --                      <ColumnValue>1</ColumnValue>        
    --                  </Param>
    --                  <Param>
    --                      <ColumnName>DepartmentName</ColumnName>
    --                      <ColumnValue>Electronics and Communication</ColumnValue>        
    --                  </Param>
    --                  <Param>
    --                      <ColumnName>BuildingNumber</ColumnName>
    --                      <ColumnValue>1</ColumnValue>        
    --                  </Param>    
    --              </Parameters>'
    
    CREATE PROCEDURE TestProc
    @parameters XML
    AS
    BEGIN
        DECLARE @temp1 TABLE
        (
              ColName VARCHAR(100)
            , ColVal VARCHAR(4000)      
        )
    
        INSERT INTO @temp1
        SELECT    Params.Col.value('ColumnName[1]', 'VARCHAR(50)') ColName
                , Params.Col.value('ColumnValue[1]', 'VARCHAR(50)') ColVal              FROM   @parameters.nodes('//Parameters/Param') Params(Col)
    
        DECLARE @sql VARCHAR(4000)
    
        SET @sql = 'SELECT * FROM Departments WHERE '
    
        SELECT @sql = @sql  + ColName + ' = ''' + ColVal  + ''' AND '
        FROM @temp1
    
        -- Trim last AND
        SET @sql = SUBSTRING(@sql, 1, LEN(@sql) - 3)
    
        PRINT @sql                  
    
        EXEC (@sql)             
    
    END
    

    On executing this proc following result is obtained
    pkDepartmentId DepartmentName BuildingNumber
    1 Electronics and Communication 1

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

Sidebar

Related Questions

I'm new to SQL. I have a large number of stored procedures in my
On my SQL Server 2008 I have a stored procedure with a large number
I have a large number of 2D points and I want to quickly get
I have a large number of csv files that look like this below: xxxxxxxx
I have a large number of C# WCF services that are being called by
How to pass a large number of parameters (say 20+) to stored procedure from
In my application, I have a large of number (100+) of rows that I
I have a SQL statement that displays the following values, but the number of
I have a SQL Server database that has a huge proliferation of stored procedures.
I have a large number of files in a .tar.gz archive. Checking the file

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.