简体   繁体   中英

How to get count of consecutive number greater than 0 in string using T-SQL Script

I want to count the consecutive number of string that is greater than 0

eg 320244434321: Result is 9 (244434321)

eg 320244434: Result is 6 (244434)

eg 321244430: Result is 8 (32124443)

eg 32012076: Result is 2 (32,12,76)

eg 320120761: Result is 3 (761)

Declare @col char(25)

Declare @col1 char(1)

Declare @col2 char(1)

Declare @col3 char(1)

Declare @dpd bigint

SET @col = '320244434321'

SELECT MAX(cons)from(

SELECT

value as val,LEN(value) as cons

FROM

STRING_SPLIT(@col, '0')

) ZZ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM