In the below table, DECLARE @t1 TABLE(id INT,NAME VARCHAR(MAX)) INSERT INTO @t1 VALUES(1,'test') INSERT INTO @t1 VALUES(2,'test') INSERT INTO @t1 VALUES(3,'best') INSERT INTO @t1 VALUES(4,'rest') INSERT INTO @t1 VALUES(5,'rest') how can I select the records that have equals values coming adjacently? That is I am running an SQL job. It should take the adjacent equal value count for its processing. In the below table, first time the job is running it should take count as 2 the 2nd time job is running it should be 1. Third time it should be 2. What is the query that will fetch the cont of equal records for name column? In case no equal columns it should be 1. Please help
SELECT [NAME], COUNT([NAME]) AS CountOfNames FROM @t1 GROUP BY [NAME]
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)