How to count the number of times a character appears in a SQL column?

前端 未结 2 1404
借酒劲吻你
借酒劲吻你 2020-12-14 00:39

For a user logging table I have in a SQL database, I track the some of the parameters off of a report request. The report allows multiple ID\'s to be passed to it and I sto

2条回答
  •  孤城傲影
    2020-12-14 00:58

    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)

提交回复
热议问题