Example and Notes
Use this SQL Server example as a starting point for development, troubleshooting, reporting, or maintenance work. Review it against your schema, data volume, permissions, and SQL Server version before using it in production.
You may have a need to find dynamic values in your table - more than one value from the same field. For example, you may want to find any record in a table that has the State value of Iowa or Missouri. This sample script will show you how to accomplish this.
DECLARE @prmSql varchar(1000)
DECLARE @prmSelect varchar(75)
DECLARE @prmCriteria varchar(75)
SET @prmSelect = 'MailingState, CustomerName'
SET @prmCriteria = '''IA'',''MO'''
SET @prmSql = 'SELECT ' + @prmSelect + ' FROM tblCustomers WHERE MailingState In (' + @prmCriteria + ')'
EXEC (@prmSql)
Production Review
WSI can adapt this script for your database, improve error handling, tune performance, document the logic, and help deploy it safely.