Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Flexible searching on tables

By kornolio,

In my company's web site there are search pages for allowing users to search info on one or more tables (or in my case a select with 10 joins). Often the requirements for these search pages change over time with users either requesting additional columns to search or remove columns that are no longer useful.

The search page that the script is based on looks like this...

Date received |______|
Area |_______|
Source of budget |______|


I came up with the following stored proc to grab results from the source table w/c still allows me flexibility when it came to adding or removing searchable columns.

The script will work but it heavily depends on having an identity key on the source table and it is necessary to be mindful of the no. of columns used in the table variable so as not to downgrade performance.

At first the delete statements will seem hard to understand then when you get the hang of it you'll appreciate the flexibility the script offers and then you're gonna send me $10,000 on my birthday.

Total article views: 225 | Views in the last 30 days: 1
Related Articles

Searching Column Name in All Tables

Use this script to search for a specific column name in all tables in a current database.


Excel Source column DataType

Excel Source column DataType issue


Search for a Column in all databases

This Script can be used for searching a column in SQL server 2005


Not displaying Columns in OLEDB Source

Not displaying Columns in OLEDB Source


Object Search for Sql Server 2005

This script will search databases, tables, columns, stored procedures for text.


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones