Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

How to Combine LIKE and IN

 
   Database Forums (Home) -> MSEQ RSS
Next:  create dynamic variable in procedure  
Author Message
Chaplain Doug

External


Since: May 13, 2008
Posts: 3



(Msg. 1) Posted: Wed May 14, 2008 7:49 am
Post subject: How to Combine LIKE and IN
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

SQL Server 2005.

I want to do a query that will accomplish both a LIKE type search and an IN
type search. I have a variable number of LIKE strings that I want to search
on. I know I can say:

SELECT * FROM <TABLE> WHERE <FIELD> LIKE '0001%' AND <FIELD> LIKE '0002%'
AND <FIELD> LIKE '0003%'

Is there a way to shorten this select statement and still accomplish the
same search? Thanks for any help.
--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org

 >> Stay informed about: How to Combine LIKE and IN 
Back to top
Login to vote
Chaplain Doug

External


Since: May 13, 2008
Posts: 3



(Msg. 2) Posted: Wed May 14, 2008 7:53 am
Post subject: Correction [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I should have put OR in my example as:

SELECT * FROM <TABLE> WHERE <FIELD> LIKE '0001%' OR <FIELD> LIKE '0002%' OR
<FIELD> LIKE '0003%'

 >> Stay informed about: How to Combine LIKE and IN 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
EXEC (select... ) problem Help! - How can I get this to work? declare @WkEmpID declare @sql varchar(1000) set @sql = 'select distinct @WkEmpID = EmpID from Employee' exec (@sql) Now this is a simplified version of a more comples query which is forcing me to use this method rather than...

Query returning multiple rows - Hi, I have a query that returns back rows that have multiple entries for a given UniqueID. I want the query to be expanded so that it then only returns 1 of the multiple rows based on the maximum date. Thefore, my return set looks like this: ..

Having a stored procedure copy tables & also preserve inde.. - Hello, I created a stored procedure that renames a table to OLD_xxxxx and replaces that table with another (copy) that resides on a different database. I pull the tablename names through the use of a cursor table and construct a SELECT INTO statement a...

GROUP BY's on 3 tables in one SELECT? - Hi there, I'd like to ask you for help with following: having 3 tables: T1 (Person_ID, Product_ID, Costs) T2 (Person_ID, Product_ID, Balancies) T3 (Product_ID, Product_Type) I have simple GROUP BY query: SELECT T1.Person_ID, T1.Product_ID, MAX(Costs)..

Query needs to loop? - Is this possible? A char variable length field contains this data: (for example) ABC,XYZ,GEF,CAB I need to query another table on the contents of each of these names that are separated by comma. I need to read ABC and then query another table for ABC in...
   Database Forums (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]