August 22, 2008 at 2:52 am
Dear friends...
I have two table EmpDetails and ProductDetails...both having CityID
as below
Create Table EmpDetails
(
Empid int primary key,
empname varchar(25),
CityId int
)
insert into EmpDetails values('1','Ashok','1')
insert into EmpDetails values('2','Rakesh','2')
insert into EmpDetails values('3','Ravi','3')
insert into EmpDetails values('4','Nilesh','4')
insert into EmpDetails values('5','prakesh','5')
Create table ProductDetails
(
ProductId int primary key,
ProductName varchar(25),
CityId varchar(25)
)
insert into ProductDetails values('1','PC','1,2')
insert into ProductDetails values('2','Book','3,4')
insert into ProductDetails values('3','Monitor','1,5,6')
insert into ProductDetails values('4','HandBook','7,8')
insert into ProductDetails values('5','Mobile','9,10')
now if i want to chech the EmpDetails.cityid is there in Productdetails.cityid .......
i have written a qurey
select EmpDetails.cityid,ProductDetails.cityId from EmpDetails,ProductDetails
where EmpDetails.cityid in (ProductDetails.cityId )
but i am not able to get ..
can anyone help me...
Ashwani kumar
August 22, 2008 at 3:01 am
Are these tables tables that you are stuck with, or did you create them yourself? In the first case, you would need to split the list into individual values. You can see how to do this on http://www.sqlservercentral.com/Forums/Topic555742-149-1.aspx. Bad design!
If you created these tables, then I'd consider changing them and not storing the cities in a single row in a column with the individual cities dumped into a comma separated list.
Regards,
Andras
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply