I want to select all the payments where varchar has a value in it

select * from payments where varchar in like %(variable1,variable2,variable3)%


I want to select all the payments where varchar has a value in it
LVL 1
rgb192Asked:
Who is Participating?
 
derekkrommConnect With a Mentor Commented:
all of them?

select * from payments where field like '%hello%' and field like '%bye%' and field like '%more%' and field like '%words%'

at least 1?

select * from payments where field like '%hello%' or field like '%bye%' or field like '%more%' or field like '%words%'

0
 
EL_BarbadoCommented:
This SQL statement will give you all payments where varchar variable has a value in it.

SELECT *
FROM Payments
WHERE @Variable1 IS NOT NULL
OR @Variable2 IS NOT NULL
OR @Variable3 IS NOT NULL
0
 
derekkrommCommented:
declare @sql nvarchar(max)
set @sql = 'select * from payments
where varcharfield like ''%' + @variable1 + '%''
or varcharfield like ''%' + @variable2 + '%''
or varcharfield like ''%' + @variable3 + '%'''

exec @sql
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
derekkrommCommented:
change exec @sql to "exec sp_executesql @sql"
0
 
rgb192Author Commented:
>>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


0
 
rgb192Author Commented:
is there a way to use IN

instead of
or field like     or field like    or field like   or field like
0
 
derekkrommCommented:
no, that will only work for exact matches of each variable
0
 
rgb192Author Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.