Solved

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

Posted on 2011-03-10
8
243 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
 

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 15

Accepted Solution

by:
derekkromm earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now