Advertisement
DataCCIW

Locate Multiple Phone Numbers of same type

Dec 30th, 2021
1,776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.38 KB | None | 0 0
  1. SELECT P.Id AS PhoneNumberId
  2.     ,M.PersonId
  3.     ,D.Value AS PhoneNumber
  4.     ,M.count_of_type
  5.     ,P.Number
  6.     ,P.Extension
  7. FROM (
  8.     SELECT personid
  9.         ,NumberTypeValueId
  10.         ,count(id) AS [count_of_type]
  11.     FROM [dbo].[PhoneNumber]
  12.     GROUP BY personid
  13.         ,NumberTypeValueId
  14.     HAVING count(id) > 0
  15.     ) M
  16. JOIN DefinedValue D ON D.Id = M.NumberTypeValueId
  17. JOIN PhoneNumber P ON P.PersonId = M.PersonId
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement