久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MySQL 的 group_concat 和轉(zhuǎn)義字符串的 SQL Server 版本

SQL Server version of MySQL#39;s group_concat and escaped strings(MySQL 的 group_concat 和轉(zhuǎn)義字符串的 SQL Server 版本)
本文介紹了MySQL 的 group_concat 和轉(zhuǎn)義字符串的 SQL Server 版本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我只有 MS SQL Server 2008 和 Visual Studio 的 Express 版本.鑒于我無法創(chuàng)建 SQL Server 項目,因此無法使用 CLR 解決方案,我嘗試使用

I only have the Express versions of MS SQL Server 2008 and Visual Studio. Given that I can't create a SQL Server project and therefore CLR solutions are out of the question, I've attempted to use

select col1, stuff( ( select ' ' + col2
from StrConcat t1
where t2.col1 = t1.col1
for xml path('')
),1,1,'')
from StrConcat t2
group by col1
order by col1

獲取連接 col2 的行.col2 是一個 varchar 字段,帶有一些控制字符,例如 &\n.當(dāng)它與上面的 SQL 連接時,它似乎轉(zhuǎn)義了那些控制字符,即.& 變成&放大器;而 \n 變成了 &#xOD,這不是我想要的.鑒于 col1 和連接字段將用于更新另一個表,那么以未轉(zhuǎn)義的原始形式獲取連接字段的最佳方法是什么,或者沒有,唯一的方法是求助于外部代碼?

to get a row concatenated col2. col2 is a varchar field with some control characters like & and \n. When it is concatenated with the above SQL, it appears to escape those control characters ie. & becomes & amp ; and \n becomes &#xOD, which is not what I want it to do. Given that the col1 and concatenated field is going to be used to update another table, what is the best way to get the concatenated field in its unescaped original form or is there none and the only way is to resort to external code?

表架構(gòu)如下所示:StrConcat (id int 主鍵, col1 int, txt varchar(80))col1 上有一個索引,txt 應(yīng)該按 col1 分組,按組內(nèi)的 id 排序.

The table schema looks like this: StrConcat (id int primary key, col1 int, txt varchar(80)) col1 has an index on it, txt should be grouped by col1, ordered by id within the group.

推薦答案

行為當(dāng)然是 設(shè)計.如果不以這種方式轉(zhuǎn)義,則查詢可能會輸出無效的 XML.

The behaviour is, of course, by design. If it didn't escape this way, the query could output invalid XML.

如果您需要在 SQL Server 中獲取未轉(zhuǎn)義的值,則必須使用 其他連接方法(遞歸CTE通常是僅次于CLR聚合和FOR XML,但最難寫).

If you need to get an unescaped value within SQL Server, then you'll have to use one of the other concatenation methods (recursive CTE is usually the next-most efficient after CLR aggregate and FOR XML, but hardest to write).

當(dāng)然,如果將其直接傳遞給應(yīng)用程序,則在那里對其進行轉(zhuǎn)義會容易得多,即使用 XmlReader .NET 中的類.

Of course, if this is being passed directly to an application, it will be much easier to unescape it there, i.e. using the XmlReader class in .NET.

這篇關(guān)于MySQL 的 group_concat 和轉(zhuǎn)義字符串的 SQL Server 版本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標(biāo)記轉(zhuǎn)換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計算值創(chuàng)建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 亚洲有码转帖 | 欧美精产国品一二三区 | 999久久久精品| 成人一区在线观看 | 国产三区视频在线观看 | 91色视频在线观看 | 欧美日韩在线不卡 | 国产一区二区三区免费观看在线 | 亚洲视频免费在线播放 | 久色视频在线观看 | 久久久久亚洲精品 | 日韩电影a| 西西裸体做爰视频 | av大片在线观看 | 国产精久久久 | 国产99在线 | 欧美 | 久久精品视频网站 | 欧美成人激情 | 日本三级电影在线看 | 欧洲一区二区在线 | 国产精品精品视频一区二区三区 | 日本一区二区三区四区 | 青青伊人久久 | 国产一区二区三区在线看 | 亚洲二区在线 | 国产亚洲高清视频 | 毛片免费观看视频 | 亚洲一区中文字幕 | www日本高清 | 草比av| 久草资源在线视频 | 中文字幕免费视频 | 国产激情三区 | www日韩高清 | 国产精品欧美一区二区 | 久久久久久九九九九 | 精品视频在线观看 | 黄a网| 久久久国产精品 | 日韩成人免费在线视频 | 国产精品永久在线观看 |