Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 'like' first 3 characters of a variable

Author  Topic 

grippa
Starting Member

2 Posts

Posted - 2012-06-20 : 03:46:50
Hi

I'm looking for a way so that i can use the like operator to work with an inner query. for example that it likes the left 3 of the result of the inner query.

so something like this:

select customerid
from customer
where ZIPcode like 'left 3' (select zipcode from customer where age = 150)

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-20 : 03:56:26
someting like this?

select customerid
from customer
where left(ZIPcode,3) in (select distinct left(zipcode,3) from customer where age = 150)


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

grippa
Starting Member

2 Posts

Posted - 2012-06-20 : 04:04:32
thanks ye thats what i needed :D:D:D
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-06-20 : 05:39:36
or

select c1.customerid
from customer as c1 inner join customer as c2 on c1.ZIPcode like left(c2.zipcode,3)+'%'
where c2.age = 150


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -