rgb192
asked on
I want to select all the payments where varchar has a value in it
select * from payments where varchar in like %(variable1,variable2,vari able3)%
I want to select all the payments where varchar has a value in it
I want to select all the payments where varchar has a value in it
declare @sql nvarchar(max)
set @sql = 'select * from payments
where varcharfield like ''%' + @variable1 + '%''
or varcharfield like ''%' + @variable2 + '%''
or varcharfield like ''%' + @variable3 + '%'''
exec @sql
set @sql = 'select * from payments
where varcharfield like ''%' + @variable1 + '%''
or varcharfield like ''%' + @variable2 + '%''
or varcharfield like ''%' + @variable3 + '%'''
exec @sql
change exec @sql to "exec sp_executesql @sql"
ASKER
>>select * from payments
where varcharfield like ''%' + @variable1 + '%''
or varcharfield like ''%' + @variable2 + '%''
or varcharfield like ''%' + @variable3 + '%'''
i would get the variables by copy and paste
how could I search to see if a varcharfield had these words IN
hello
bye
more
words
where varcharfield like ''%' + @variable1 + '%''
or varcharfield like ''%' + @variable2 + '%''
or varcharfield like ''%' + @variable3 + '%'''
i would get the variables by copy and paste
how could I search to see if a varcharfield had these words IN
hello
bye
more
words
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
is there a way to use IN
instead of
or field like or field like or field like or field like
instead of
or field like or field like or field like or field like
no, that will only work for exact matches of each variable
ASKER
thanks
SELECT *
FROM Payments
WHERE @Variable1 IS NOT NULL
OR @Variable2 IS NOT NULL
OR @Variable3 IS NOT NULL