在一行中显示不同的类别名称 [英] Display different category name in a single row

查看:59
本文介绍了在一行中显示不同的类别名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码:

i used this code:

SELECT distinct members.name, 
       REPLACE(RTRIM((SELECT CAST([cat_name] AS VARCHAR(MAX)) + ' ' 
  FROM category 
          INNER JOIN specialisation 
             ON category.cat_id=specialisation.cat_id 
 WHERE (member_id = members.member_id) FOR XML PATH (''))),' ',', ') AS cat_name 
  FROM specialisation 
       INNER JOIN members 
          ON specialisation.member_id = members.member_id 
       INNER JOIN city_list 
          ON members.city = city_list.city_id 
       INNER JOIN category 
          ON specialisation.cat_id = category.cat_id 
       INNER JOIN state_list 
          ON members.state = state_list.state_id where qualification_id=1




但我得到了这样的结果:


名称cat_name
---------- ----------------------------------------
sanjit银行,市场营销
rajiv商业,法律,民事,法律,家庭,法律

每个词都用逗号分隔,但我需要商业法,民法,家庭法

请任何人可以帮助我

谢谢


我使用了经典的asp并显示了<%= rs("cat_name")%>




but i got the result like this:


name cat_name
---------- ----------------------------------------
sanjit Banking, marketing
rajiv Business, law,civil,law,family,law

every word is separated by comma but i need like Business law,civil law,family law

please any one can help me

Thanks


I used classic asp and display data like this <%=rs("cat_name")%>

推荐答案

^ ]是使用SQL 2005或更高版本的最佳方法
Pivot[^] is the best way if you are using SQL 2005 or later


只需使用字符串替换功能.

Simply use string replace function.

Dim str As String
        str = "dreamz, 9"
        errorfound.Text = str.Replace(", ", ",")
        errorfound0.Text = str


这篇关于在一行中显示不同的类别名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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