terpster73
IS-IT--Management
I have the following and I need to have the variables 'search' for data that 'contains' the data a user enters. Eg. For either OWNNAME1 or OWNNAME2 A user types in mont and they would get records that matched Montana, and Fairmont. How can I Acheive this with what I already have?
DECLARE @sql nvarchar(4000)
SELECT @sql = ' SELECT OWNNAME1, OWNNAME2, OWNADD1, OWNADD2, OWNCITY, OWNSTATE, OWNERZIP ' +
' FROM dbo.HOWA WHERE 1 = 1 '
IF @OWNNAME1 IS NOT NULL
SELECT @sql = @sql + ' AND OWNNAME1 LIKE @OWNNAME1 '
IF @OWNNAME2 IS NOT NULL
SELECT @sql = @sql + ' AND OWNNAME2 LIKE @OWNNAME2 '
EXEC sp_executesql @sql, N'@OWNNAME1 nvarchar(100), @OWNNAME2 nvarchar(100)',
@OWNNAME1, @OWNNAME2
DECLARE @sql nvarchar(4000)
SELECT @sql = ' SELECT OWNNAME1, OWNNAME2, OWNADD1, OWNADD2, OWNCITY, OWNSTATE, OWNERZIP ' +
' FROM dbo.HOWA WHERE 1 = 1 '
IF @OWNNAME1 IS NOT NULL
SELECT @sql = @sql + ' AND OWNNAME1 LIKE @OWNNAME1 '
IF @OWNNAME2 IS NOT NULL
SELECT @sql = @sql + ' AND OWNNAME2 LIKE @OWNNAME2 '
EXEC sp_executesql @sql, N'@OWNNAME1 nvarchar(100), @OWNNAME2 nvarchar(100)',
@OWNNAME1, @OWNNAME2