Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-10
8
Medium Priority
?
260 Views
Last Modified: 2012-05-11
select * from payments where varchar in like %(variable1,variable2,variable3)%


I want to select all the payments where varchar has a value in it
0
Comment
Question by:rgb192
  • 4
  • 3
8 Comments
 
LVL 2

Expert Comment

by:EL_Barbado
ID: 35096291
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
 
LVL 15

Expert Comment

by:derekkromm
ID: 35096338
declare @sql nvarchar(max)
set @sql = 'select * from payments
where varcharfield like ''%' + @variable1 + '%''
or varcharfield like ''%' + @variable2 + '%''
or varcharfield like ''%' + @variable3 + '%'''

exec @sql
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 35096350
change exec @sql to "exec sp_executesql @sql"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:rgb192
ID: 35096664
>>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
 
LVL 15

Accepted Solution

by:
derekkromm earned 2000 total points
ID: 35096673
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
 

Author Comment

by:rgb192
ID: 35097220
is there a way to use IN

instead of
or field like     or field like    or field like   or field like
0
 
LVL 15

Expert Comment

by:derekkromm
ID: 35097298
no, that will only work for exact matches of each variable
0
 

Author Closing Comment

by:rgb192
ID: 35152622
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question