Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi friends,

I have one table with cityid(int), cityname(string).

My table (City) will be like:
City_ID    City_Name
1          Bengaluru
2          Hyderabad
3          Chennai
4          Goa
5          Kerala


In another table i have a field like city(values will be like '428,29,33')
I want to retrieve city names like ('bangalore,hyderabad,chennai').

My table (emp) like:
Emp_Name     Emp_ID    Emp_Location    Emp_Desig
Peter        1         1,2,3           Developer
Sam          2         2,3,4           Hr
Prem         3         3,4,5           TechLead
Saketh       4         4,5,1           Designer


When want retrieve data from emp table I need data like
Emp_ID    Emp_Location
1         Bengaluru, Hyderabad, Chennai
2         Hyderabad, Chennai, Goa
3         Chennai, Goa, Kerala


Can you please tell me how to do it?

Thanks in advance.
Posted
Updated 25-Sep-12 9:28am
v2
Comments
[no name] 22-Sep-12 6:48am    
You write a query to get the data that you want. That's how you do it.
V_R 22-Sep-12 7:07am    
What your doubt solved, That is all about JOINS.
ramuAlla 22-Sep-12 7:12am    
I need like ; This format ....
ramuAlla - 53 secs ago
My table (City) will be like:
City_ID City_Name
1 Bengaluru
2 Hyderabad
3 Chennai
4 Goa
5 Kerala

My table (emp) like:
Emp_Name Emp_ID Emp_Location Emp_Desig
Peter 1 1,2,3 Developer
Sam 2 2,3,4 Hr
Prem 3 3,4,5 TechLead
Saketh 4 4,5,1 Designer


When want retrieve data from emp table I need data like

Emp_ID Emp_Location
1 Bengaluru, Hyderabad, Chennai
2 Hyderabad, Chennai, Goa
3 Chennai, Goa, Kerala

You need to parse string using specific delimiters. Please, read this article: http://www.wisesoft.co.uk/scripts/t-sql_cte_split_string_function.aspx[^] and customize the function to your needs.
 
Share this answer
 
SQL
SELECT T2.CityName 
FROM Table1 T1 INNER JOIN
Table2 T2 ON T1.cityid=T2.cityid

Hope this will help you..
 
Share this answer
 
u have two table(table1 and table2) ,first table has two columns cityid and cityname and second table has one column city so u should try this
SQL
select table1.cityname from table1 where 
table1.cityid=table2.city

HOPE THIS WILL HELP U.
THANKS
 
Share this answer
 
v2
u first retrive data using this query
SQL
select empid,emploc from city,emplotee where emp_city_id=city_id
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900