Click here to Skip to main content
15,995,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi....
i am using sqlserevr 2000
my problem is

i want to count the distinct values in a row

SQL
create table counting(id int identity(1,1),[name] varchar(20),c1 varchar(10),c2 varchar(10),c3 varchar(10),[count] int default 0)

insert into counting([name],c1,c2,c3) values(aravind,AA,BB,CC)
insert into counting([name],c1,c2,c3) values(aravd,AA,AA,DD)
insert into counting([name],c1,c2,c3) values(avid,AA,AA,AA)
insert into counting([name],c1,c2,c3) values(a,AA,B,BB)
insert into counting([name],c1,c2,c3) values(arnd,EE,FF,JJ)

now i want to count the distinct values from c1,c2,c3 of one row

for example for row 1 count=3
for row 1 count=2 without using temp table

thanks in advance
Posted
Updated 14-May-10 0:27am
v2

1 solution

If the columns values are repeated then you would be better of normalizing the table and creating another table to hold those values, from there it just a select distinct count
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900