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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:49:54+00:00 2026-05-18T09:49:54+00:00

I am a bit puzzled about the best way to construct a stored procedure

  • 0

I am a bit puzzled about the best way to construct a stored procedure that returns a SELECT-statement based on table row values in another table.

The problem might be best described as this:

Table Name: reportValues
--------------------------------------------
ID       name       date        region
--------------------------------------------
1        Stefan     2010-01-01  UK
2        David      2010-01-05  SE
3        Anna       2010-01-12  NO
4        Marie      2010-01-15  NO


Table Name: reportParameters
-------------------------------
ID       column     queryValue 
-------------------------------
1        ID       
2        name     
3        date       
4        region     

Based on what the user enters in the queryValue column in the reportParameters table, I want to construct a stored procedure what executes a SELECT-statement such as this:

SELECT * FROM reportValues WHERE region = 'NO' 

If the user had entered the following values:

Table Name: reportParameters
-------------------------------
ID       column     queryValue 
-------------------------------
1        ID       
2        name       
3        date       
4        region     NO

But it might as well be:

SELECT * FROM reportValues WHERE region = 'NO' AND name = 'Anna'

If the user had entered:

Table Name: reportParameters
-------------------------------
ID       column     queryValue 
-------------------------------
1        ID       
2        name       Anna
3        date       
4        region     NO

My initial thought of doing it was to make a loop that constructs the SELECT-statement into a string variable and executes it. But it got to be a more elegant 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-05-18T09:49:55+00:00Added an answer on May 18, 2026 at 9:49 am

    I’m not sure there is, if the queries have a small, known, set of fields, then you could list them all in the where accompanied a selector:

    (IF NOT NULL reportParameters.field AND reportParameters.field = reportValues.field)
    

    There is no short-circuit evaluation, but it might still have the desired effect. Otherwise it is down to dynamic SQL and EXEC().

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

Sidebar

Related Questions

I'm a bit puzzled about Zend Framework modules. I mean - I understand that
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float
After reading a bit more about how Gnutella and other P2P networks function, I
I am a little bit puzzled as to how I can optimize my program
I am a bit puzzled by this strange behavior on CentOs 5.4 when starting
Thanks for answers,Actually I am not puzzled about draw 1024*768 pixels is slower than
I have a situation that has puzzled me for weeks. I am running logic
I am a bit puzzled reading this: Gcc 4.5 online manual --- Standards section
I'm a bit puzzled how I'm supposed to use the HTML5 <header> , <section>
I'm a bit puzzled by the number of developers I see writing methods and

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.