【发布时间】:2012-06-29 03:38:25
【问题描述】:
我是 SQL Server 的新手,我尝试了一些从互联网上建议的技术,例如使用临时变量、XML 路径、COALESCE 等,但都无法满足我的要求。
我正在使用 Toad for SQL Server 5.5 版创建 SQL 脚本,而我用来查询数据库服务器的帐户只有读取权限。因此我相信不能使用CREATE VIEW 声明。
表名:Customer
ServerName Country contact
---------- ------- -------------
srv1 SG srv1_contact1
srv1 SG srv1_contact2
srv1 SG srv1_contact3
srv2 HK srv2_contact1
srv2 HK srv2_contact2
srv3 JP srv3_contact1
srv3 JP srv3_contact2
srv3 JP srv3_contact3
srv4 KR srv4_contact1
预期输出:
ServerName Country contact
---------- ------- -------------------------------------------
srv1 SG srv1_contact1; srv1_contact2; srv1_contact3
srv2 HK srv2_contact1; srv2_contact2
srv3 JP srv3_contact1; srv3_contact2; srv3_contact3
srv4 KR srv4_contact1
【问题讨论】:
-
不确定视图有什么帮助。此外,如果您发布您尝试过的 XML 路径查询,我们可能会告诉您为什么它不符合您的要求(我们不知道“不知何故”是什么意思)。
-
请参阅stackoverflow.com/questions/1874966/… 以获得更好的解决方案。
标签: sql sql-server sql-server-2008 tsql