Link to home
Start Free TrialLog in
Avatar of Allan
AllanFlag for United States of America

asked on

T-SQL - Get Same Address1 with Different Address2

Hi Experts!

Have the following data and need a query to find the Pid that has same
Address1, but different Address2.
Query should RETURN 1, 4, and 5 -- this is for SQL Server 2012

DECLARE @PersonAddress TABLE
(
  PiD int, 
  Address1 varchar(50),
  Address2 varchar(50)
)

INSERT INTO @PersonAddress (PiD, Address1, Address2)
 SELECT 1, '123 ABC St', 'Suite 201' UNION
 SELECT 1, '123 XYZ St', 'Suite 201' UNION
 SELECT 1, '123 Cookie St', 'Suite 201' UNION
 SELECT 1, '123 ABC St', 'Suite 201' UNION
 SELECT 1, '123 ABC St', 'Suite 301' UNION
 SELECT 2, '457 Marvel St', 'Suite 1001' UNION
 SELECT 2, '1 DownTown Lane', '' UNION
 SELECT 3, '2 Busy Rd', 'Apt 2001' UNION
 SELECT 3, '2 Busy Ave', 'Apt 20' UNION
 SELECT 3, '2 Busy Ave', 'Apt 20' UNION
 SELECT 4, '10 CutOver Lane', 'Suite 201' UNION
 SELECT 4, '10 CutOver Lane', 'Suite 301' UNION
 SELECT 4, '10 CutOver Lane', 'Suite 401' UNION
 SELECT 5, '10 CutOver Lane', 'Suite 201' UNION
 SELECT 5, '10 CutOver Lane', 'Suite 301' UNION

Open in new window


TIA!
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Allan

ASKER

nice St. Jimbo; didn't think of that.