How many consecutive descending numbers in my number?

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

USE master
DECLARE @ varchar(max) = '2019';
       
WITH C as
(
  SELECT
	left(@,row_number()over(order by 1/0))+0t,
	@+null z,
	0i
  FROM
    spt_values
  UNION ALL
  SELECT
    t-1,
	concat(z,t),
	i+1
  FROM C
  WHERE i<9
)
SELECT max(i)
FROM C
WHERE z=@

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results