从SQLSERVER2008获取数据. [英] Getting Data from SQLSERVER2008..

查看:81
本文介绍了从SQLSERVER2008获取数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我有一张带有cityid(int),cityname(string)的表.

我的桌子(城市)将是:

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



在另一个表中,我有一个类似city的字段(值将类似于"428,29,33")
我想检索城市名称(例如班加罗尔,海得拉巴,金奈").

我的表格(emp)如下:



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



当要从emp表中检索数据时,我需要类似
的数据



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.

推荐答案

您需要使用特定的定界符来解析字符串.请阅读以下文章: http://www.wisesoft.co.uk/scripts/t-sql_cte_split_string_function. aspx [ ^ ]和根据需要定制功能.
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.


SELECT T2.CityName 
FROM Table1 T1 INNER JOIN
Table2 T2 ON T1.cityid=T2.cityid

Hope this will help you..


您有两个表(table1和table2),第一个表有两列cityid和cityname,第二个表有一个列city,所以您应该试试这个
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
select table1.cityname from table1 where 
table1.cityid=table2.city


希望可以帮助您.
谢谢


HOPE THIS WILL HELP U.
THANKS


这篇关于从SQLSERVER2008获取数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆