Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I use wildcard values in LIKE query using fieldname not string 1

Status
Not open for further replies.

mikemackay

Programmer
Oct 22, 2001
4
GB
hi everyone

I need to compare two fields in a LIKE query instead of a field and a string value. How do I put in wildcards in this query where start_date and end_date are field names:
'WHERE start_date LIKE end_date'. Can anyone help?
Mike



 
Try

select *
from table1
where start_date like '%'+ltrim(rtrim(end_date))+'%'

or

select *
from table1
where start_date like ltrim(rtrim(end_date))+'%'

Good luck ...
Salim
 

Why do you need to use LIKE? Why not use start_date = end_date? Do the fields have times that you don't want to compare? Have you considered using the Convert function. It is documented in SQL BOL. See the topic "Cast and Convert." Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
sguslan. Thanks very much. The code was exactly what I wanted. Thanks also for the quick response. Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top