Count rows where value differs I have the following dataset in SQL Server:

Name     Pattern
-------  -------
Peter    DRF  
Peter    DRF
Peter    BBB
Peter    DRF
Peter    CCC
Peter    CCC
Sue      DRF
Sue      CCC
Sue      DRF
Sue      VVV
Sue      SSS


I need to count the number of times a pattern changes per Name (not only distinct changes). So my end result will be:

Peter 3    
Sue 4


In other words, only counting the distinct changes. Peter changed from DRF to BBB to CCC and Sue changed from DRF to CCC to DRF to VVV to SSS.

Is this possible without using a cursor?

I have a start date and end date per row, but no unique id. Patterns gets logged by the system per person per day and sometimes multiple times per day per person.
Try this:

Declare @T table (name varchar(10), Pattern varchar(10))
insert into @t (name, Pattern) values
('Peter', 'DRF'),
('Peter', 'DRF'),
('Peter', 'BBB'),
('Peter', 'DRF'),
('Peter', 'CCC'),
('Peter', 'CCC'),
('Sue', 'DRF'),
('Sue', 'CCC'),
('Sue', 'DRF'),
('Sue', 'VVV'),
('Sue', 'SSS')

SELECT NAME
    ,count(DISTINCT pattern) AS DistinctChanges
FROM @t
GROUP BY NAME




| name  | DistinctChanges |
|-------|----------------|
| Peter | 3              |
| Sue   | 4              |




Note: There is a difference between distinct values and the number of times a value changed assuming some kind of timeline.  

For example:
AAA, BBB, AAA, BBB, AAA, BBB, AAA would be 2 distinct changes, but 5 total times the value changed assuming some sort of order.

Which variation are you looking for?