I wnat to get all customer ID who occupied in a particular location.{ID} ie
IF i pass 2 as locationID i should get the customer with ID 1 and 2 , if i pass 8 only return the customer occupied in location with id 8 here it will be 3.
Select * from Customer where Locations like '%2%';
it will return all the values has 2 i.e. 2,12,20,21,22,23,...
Then how to proceed any idea?....
Your learning journey never ends. You will have to keep learning as long as you’re alive!
Happy Coding!!!
Please ✓ Mark as Answer if the post helps you to resolving this...
binson143
Member
472 Points
189 Posts
How to solve this problem using sql query
Mar 15, 2013 08:26 AM|LINK
Dear all,
I have two table
Table: Customer
CustomerID Locaions(Varchar10)
1 2,4,3
2 2,5,7
3 8,3,9
Table Route_Location
RouteID LocationID
1 2
1 3
1 8
2 5
2 8
My problem is:
I wnat to get all customer ID who occupied in a particular location.{ID} ie
IF i pass 2 as locationID i should get the customer with ID 1 and 2 , if i pass 8 only return the customer occupied in location with id 8 here it will be 3.
How i can achive this using T-Sql
Pbalan.in
Contributor
2144 Points
484 Posts
Re: How to solve this problem using sql query
Mar 15, 2013 08:49 AM|LINK
Try this...
Select * from Customer where Locations like '%2%';
Select * from Customer where Locations like '%8%';
Dont forget to mark as answer
prabu.raveen...
Contributor
5032 Points
956 Posts
Re: How to solve this problem using sql query
Mar 15, 2013 08:58 AM|LINK
Try as below,
Select * from Customer where Location like '%,2' or Location like '2,%' or Location like '%,2,%'
gaikwad_anil...
Contributor
2805 Points
534 Posts
Re: How to solve this problem using sql query
Mar 15, 2013 09:00 AM|LINK
Select * from Customer t where t.Locations like '%2%'
OR
Select * from Customer t where t.Locations like '%8%'
www.thecodekey.com
Please mark as answer if useful
oned_gk
All-Star
35998 Points
7348 Posts
Re: How to solve this problem using sql query
Mar 15, 2013 09:08 AM|LINK
If you want to joint the table use
Suwandi - Non Graduate Programmer
prabu.raveen...
Contributor
5032 Points
956 Posts
Re: How to solve this problem using sql query
Mar 15, 2013 09:09 AM|LINK
Hi,
dont try as below,
Select * from Customer where Locations like '%2%';
it will return all the values has 2 i.e. 2,12,20,21,22,23,...
jbkumar
Participant
1638 Points
315 Posts
Re: How to solve this problem using sql query
Mar 15, 2013 01:23 PM|LINK
Then how to proceed any idea?....
Happy Coding!!!
Please ✓ Mark as Answer if the post helps you to resolving this...
prabu.raveen...
Contributor
5032 Points
956 Posts
Re: How to solve this problem using sql query
Mar 16, 2013 04:50 PM|LINK
Try as below,
Select * from Customer where (','+Locations+',') like '%,2,%';
oned_gk
All-Star
35998 Points
7348 Posts
Re: How to solve this problem using sql query
Mar 16, 2013 06:00 PM|LINK
Suwandi - Non Graduate Programmer