Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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 |______|

[Submit]

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: 226 | Views in the last 30 days: 1
 
Related Articles
SCRIPT

Searching Column Name in All Tables

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

FORUM

Excel Source column DataType

Excel Source column DataType issue

SCRIPT

Search for a Column in all databases

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

FORUM

Not displaying Columns in OLEDB Source

Not displaying Columns in OLEDB Source

SCRIPT

String Search

Search for a string value within columns of data types CHAR, NCHAR, NTEXT, NVARCHAR, TEXT, VARCHAR, ...

Tags
miscellaneous    
 
Contribute