2016-05-23 21 views
-1

例如,我有100001,100002,存儲在NVARCHAR列中。有什麼方法可以統計SQL Server中NVARCHAR列的字符數?

我想要計算此列中,的出現次數。

+0

'選擇LEN(COL) - len(替換(col,',',''))' –

+0

@juergen d:太糟糕了;你的評論應該是我的答案:-) –

+0

@ThorstenKettner就像你沒有回答,因爲有[大量](http://stackoverflow.com/questions/9789225/number-of-times-a-particular-字符出現在一個字符串中)[of](http://stackoverflow.com/questions/287373/how-can-you-find-the-number-of-occurrences-of-a-particular-character-在字符串中)[dupe](http://stackoverflow.com/questions/738282/how-do-you-count-the-number-of-occurrences-of-a-certain-substring-in-a- sql-varch)目標! – DavidG

回答

0

選擇LEN( '100001,100002,') - LEN(替換( '100001,100002,', '', ''))

返回2

+0

這已經寫在評論中,是什麼讓你的答案更好? – DavidG

+0

不是。我敢肯定,如果你看了時間戳,你會發現我們幾乎同時發佈了。 –

+0

差11分,但仍然。 '2016-05-23 16:23:49Z' - >'2016-05-23 16:34:39Z' – Tom

相關問題