Skip to content
Advertisement

How to check consecutive values in rows in TSQL?

I have the following table:

strong text

And I am looking for an output like this with a consecutive available two slots. Preferably the consecutive number should be a variable like @n = 2.

enter image description here

How to achieve this in TSQL? Thanks!

Update 8/3/2022:

I undeleted this question as it is not fair to @lptr, as he/she has the correct solution, but didn’t put that in answer section.

Sean Lange: Sorry, my question was not very clear for the first time, but basically the query is looking at the SLOT column with Available=Y data, and need to output the first occurrence of the row where SLOT numbers are “N” consecutive numbers, in this case 2.

Advertisement

Answer

Posting this on behalf of @lptr:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement