Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Selecting ROWS that have different values in a var

Author  Topic 

jayram11
Yak Posting Veteran

97 Posts

Posted - 2010-10-07 : 14:46:57
Hi
i have table i want to select records where for one variable where there are two distinct values

the table is A and i want to select hcpcs that have more than one value
the table is like this
hcpcs Values
a 0
a 0
a 1
b 0
b 1
b 0
c 0
c 0
c 0
d 1
d 0
d 1
e 0
e 0
e 0

i want to select records where the value changes within that group by HCPCS

so i basically want

hcpcs Values
a 0
a 0
a 1
b 0
b 1
b 0
d 1
d 0
d 1


THanks

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-10-07 : 14:55:24
SELECT * FROM A
WHERE hcpcs IN (SELECT hcpcs FROM A GROUP BY hcpcs HAVING COUNT(DISTINCT Values)>1)
Go to Top of Page

jayram11
Yak Posting Veteran

97 Posts

Posted - 2010-10-07 : 15:29:30
Thanks
Go to Top of Page
   

- Advertisement -