Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.86 KB | None | 0 0
  1. SELECT DISTINCT
  2.   T1.[id] AS "index",
  3.   T1.[Family_ID] AS "Fam_id",
  4.   REPLACE([MART_SubjectInformation].[subject_code],'.','') AS "subject_code",
  5.   CASE
  6.     WHEN [MART_SubjectInformation].[sex] = 'Male' THEN 'm'
  7.     WHEN [MART_SubjectInformation].[sex] = 'Female' THEN 'f'
  8.     ELSE [MART_SubjectInformation].[sex]
  9.   END AS "sex",
  10.   CASE
  11.     WHEN T1.[Affected_status] = 'Affected' THEN '1'
  12.     WHEN T1.[Affected_status] = 'Unaffected' THEN '0'
  13.     ELSE T1.[Affected_status]
  14.   END AS "affected",
  15.   CASE
  16.     WHEN [MART_SubjectInformation].[mother_code] IS NOT NULL THEN REPLACE([MART_SubjectInformation].[mother_code],'.','') --+'subjrec' --use this to visualize which data source the parent subject code is coming from
  17.     WHEN T3.[subject_code] IS NULL THEN 'NA'
  18.     ELSE REPLACE(T3.[subject_code],'.','')
  19.   END AS "mom",
  20.   CASE
  21.     WHEN [MART_SubjectInformation].[father_code] IS NOT NULL THEN REPLACE([MART_SubjectInformation].[father_code],'.','') --+'subjrec' --use this to visualize which data source the parent subject code is coming from
  22.     WHEN T2.[subject_code] IS NULL THEN 'NA'
  23.     ELSE REPLACE(T2.[subject_code],'.','')
  24.   END AS "dad",
  25.   CASE
  26.     WHEN [MART_SubjectInformation].[mortality_status] = 'Alive' THEN '1'
  27.     WHEN [MART_SubjectInformation].[mortality_status] = 'Dead' THEN '0'
  28.     ELSE [MART_SubjectInformation].[mortality_status]
  29.   END AS "alive"
  30. FROM [MART_SubjectInformation]
  31. INNER JOIN [MART_EX_FORM_UDP_next_gen_seq_status] T1
  32.   ON [MART_SubjectInformation].[subject_id] = T1.[subject_id]
  33. LEFT JOIN [MART_EX_FORM_UDP_next_gen_seq_status] T2
  34.   ON T1.[Family_ID] = T2.[Family_ID]
  35.   AND T1.[Relationship] NOT IN ('Father','Mother')
  36.   AND T2.[Relationship] = 'Father'
  37. LEFT JOIN [MART_EX_FORM_UDP_next_gen_seq_status] T3
  38.   ON T1.[Family_ID] = T3.[Family_ID]
  39.   AND T1.[Relationship] NOT IN ('Father','Mother')
  40.   AND T3.[Relationship] = 'Mother'
  41. ORDER BY T1.[Family_ID], "subject_code"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement