SQLTeam.com | Weblogs | Forums

How to count the pairs of two columns with unmatched values?


I have two columns and I want to count the rows where the value in Col1 is not the same as the value in Col2.

I tried some code but I got some errors.

What code could do that please?


use sqlteam

declare @salfor table(col1 int, col2 int)

insert into @salfor
select 1,1 union
select 1,2 union
select 1,3 union
select 1, 4

select count(1) 
 From @salfor
 where col1 <> col2