Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.43 KB | None | 0 0
  1. WITH P AS (
  2. SELECT DISTINCT
  3.     College.Id AS CollegeId,
  4.     Degree.Id AS DegreeId,
  5.     CASE WHEN Master.Online IS NULL THEN 'False' ELSE 'True' END AS Online,
  6.     Master.FacebookUrl,
  7.     Master.InsideInformation,
  8.     Master.DegreeUrl,
  9.     Master.AdmissionsUrl
  10. FROM MasterData3 Master
  11. INNER JOIN (SELECT * FROM (VALUES (0,4),(1,2),(2,1)) AS Map(x,y)) AS Map    -- get degree category
  12.     ON Map.x=DegreeCategory
  13. INNER JOIN SearchItem                                                       -- get searchitem
  14.     ON SearchItem.Name=Master.SubjectData
  15. INNER JOIN Subject                                                          -- get subject
  16.     ON Subject.Id = SearchItem.Id
  17. INNER JOIN Institution                                                      -- get institution
  18.     ON Institution.Name = Institution
  19. INNER JOIN College                                                          -- get college
  20.     ON College.Name = [College]
  21.     AND College.InstitutionId = Institution.Id
  22. INNER JOIN DegreeType                                                       -- get degreetype
  23.     ON  DegreeType.Abbreviation=Master.DegreeType
  24.     AND DegreeType.DegreeCategoryId=Map.y
  25. INNER JOIN Degree                                                           -- get degree
  26.     ON  Degree.SubjectId=Subject.Id
  27.     AND Degree.DegreeTypeId=DegreeType.Id
  28. ),
  29. Q AS (
  30. SELECT
  31.     CollegeId,
  32.     DegreeId,
  33.     MIN(Online) AS Online,
  34.     MIN(FacebookUrl) AS FacebookUrl,
  35.     MIN(InsideInformation) AS InsideInformation,
  36.     MIN(DegreeUrl) AS DegreeUrl,
  37.     MIN(AdmissionsUrl) AS AdmissionsUrl,
  38.     COUNT(*) AS COUNT
  39. FROM P
  40. GROUP BY CollegeId, DegreeId
  41. )
  42. INSERT INTO dbo.[Program]
  43. SELECT CollegeId, DegreeId, Online, FacebookUrl, InsideInformation, DegreeUrl, AdmissionsUrl FROM Q
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement