Solved

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

Posted on 2011-03-10
8
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
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 …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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