This seems to work - but you didn't post your expected output based on your sample so I'm not sure.declare @t table (Driver# int, start varchar(2), stop1 varchar(2), stop2 varchar(2))insert @tselect 001, 'LA', 'FL', 'LA' union allselect 002, 'MS', 'LA', null union allselect 003, 'SC', 'FL', 'LA'select driver# ,case when start != stop1 then 1 else 0 end + case when stop1 != stop2 then 1 else 0 end as movesfrom @tOUTPUT:driver# moves----------- -----------1 22 13 2
EDIT:I just looked at your code that you said works and I'm confused because I don't even see any references to the columns you said are in your table? (start stop1, stop2)Be One with the OptimizerTG