且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何计算一个字符在 SQL 列中出现的次数?

更新时间:2022-04-11 08:19:08

SELECT LEN(RequestedReportParams) - LEN(REPLACE(RequestedReportParams, ',', ''))
FROM YourTable
WHERE .....

这只是将列的长度与逗号进行比较,将值的长度与删除逗号进行比较,以得出差异(即逗号的数量)

This is simply comparing the length of the column with the commas, with the length of the value with the commas removed, to give you the difference (i.e. the number of commas)