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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:37:50+00:00 2026-06-12T02:37:50+00:00

I have an ASP.NET MVC 3 app that lets users to create their own

  • 0

I have an ASP.NET MVC 3 app that lets users to create their own filters. Something like amount > 5 and amount <= 7, and so on. The user can choose both the amount value and the operator.

My problem is how to pass those filters to the stored procedure that retrieves the data. The stored procedure is already pretty complicated, meaning there are a lot of parameters passed which are checked to be null, so I can’t really apply the answer I found here: T-SQL Stored Procedure – Dynamic AND/OR Operator

Is there any other way I can do 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-06-12T02:37:51+00:00Added an answer on June 12, 2026 at 2:37 am

    Operators cannot be parameterized. Since you mention this is a stored procedure, the only option is to write the T-SQL inside the SP, and use sp_executesql, i.e.

    //TODO : verify (whitelist) that @operator is in a known set of values...
    // '=', '<>', '>', '<' etc - otherwise security risk
    declare @sql varchar(4000) = 'select * from Foo where Bar '
              + @operator + ' @value'
    exec sp_executesql @sql, N'@value int', @value
    

    This builds the query (@sql) on the fly, but keeps the value (@value) parameterized throughout, so we only need to white-list the operator (@operator).

    Just to show how the value remains parameterized, we could also have used:

    //TODO : verify (whitelist) that @operator is in a known set of values...
    // '=', '<>', '>', '<' etc - otherwise security risk
    declare @sql varchar(4000) = 'select * from Foo where Bar '
              + @operator + ' @p'
    exec sp_executesql @sql, N'@p int', @value
    

    Here, @p is the name of the parameter in the inner sql, and @value is the name of the parameter in the stored procedure; the third/fourth/fifth/etc parameters to sp_executesql are mapped to the parameters declared in the second parameter to sp_executesql (which in this example, declared just @p).

    Note that if this wasn’t a stored procedure, you could perform the query-construction step in C#, again keeping the value as a parameter.

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

Sidebar

Related Questions

So, I have an asp.net mvc app that is being worked on by multiple
I have an ASP.NET MVC 3 app that is using SQL Server CE 4.0
I have an asp.net mvc web app that has controllers with role attributes on
I'm working on an ASP.NET MVC App that has buttons that have the server
I have a relatively simple ASP.net MVC 2 app that is using SubSonic. Everything
I have a route defined last in my ASP.Net MVC 2 app that will
I have this ASP.NET MVC app that I've deployed on IIS6/Win2003 as a virtual
I have an asp.net MVC App that I want to deploy to IIS 5
I have asp.net mvc app that shows varios events. All events stored in a
I have an ASP.NET MVC app that I have been building, and I am

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.