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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:07:20+00:00 2026-05-26T22:07:20+00:00

I’m trying to modify a stored procedure used in an ASP.NET page. By default,

  • 0

I’m trying to modify a stored procedure used in an ASP.NET page.

By default, the stored procedure returns all of the data, which can be overwhelming for employees in the plant.

I want to add a drop down menu item for the column name and a text box for a value to allow our employees to search the data for their specific items.

What I would like to add is the ability to pass in a Column Name and Column Value to search, similar to the following:

DECLARE @colName nVarChar(50), @colValue nVarChar(50)
SET @colName='EmployeeID'
SET @colValue='007135'
SELECT  Column1, Column2, Column3, Column4, Column5, Column6, Column7
FROM    viewNum1
WHERE   ((@colName IS NULL) OR (@colValue IS NULL) OR ('['+@colName+']'=@colValue))

If all values passed in (@colValue and @colName), all records return; however, if I try specifying that @colName=EmployeeID and @colValue=’007135′ (a value that does exist in the database), no records are returned.

Next is the problem that I am running an old SQL Server 2000 database that does not allow the stored procedure to access the table column names, and the whole technique looks prone to SQL Injection.

Finally, I don’t see how to bind my GridView control to this and still have the ability to display all records.

How would I write such a filtering stored procedure?

  • 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-26T22:07:21+00:00Added an answer on May 26, 2026 at 10:07 pm

    I would definitely not recommend doing this with any critical database. As it opens you up to easy attacks on your data but since you asked below will do the trick for you:

    DECLARE @colName nVarChar(50) = NULL;
    DECLARE @colValue nVarChar(50) = NULL;
    
    DECLARE @sql = 'SELECT Column1,Column2,Column3,Column4,Column5,Column6,Column7 FROM viewNum1 WHERE 1=1 ';
    
    if ISNULL(@colName,'')<>'' AND ISNULL(@colValue,'')<>''
        SET @sql = @sql + ' AND ' + @colName + '=''' + @colValue + '''';
    
    
    exec(@sql);
    

    I would recommend you instead create a proc with nullable parameters for each column as it is safer:

    CREATE PROCEDURE dbo.ProcName
        @Column1 as nvarchar(50) = NULL,
        @Column[n] as [dbtype] = NULL
    AS
    BEGIN
    
    SELECT Column1, Column[n]...
    FROM viewNum1
    WHERE
    ((@Column1 IS NULL) OR (Column1 = @Column1))
    AND ((@Column[n] IS NULL) OR (Column[n] = @Column[n]))...
    
    END
    
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.