Solved

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

Posted on 2011-03-10
8
241 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

19 Experts available now in Live!

Get 1:1 Help Now