Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. select C.Description,s.Description
  2. from category C
  3. inner join SubCategory S on C.CategoryID =S.CategoryID
  4. where C.IsActive=1 and S.IsActive=1
  5.  
  6. DROP TABLE IF EXISTS #temp
  7. CREATE TABLE #temp ( Description VARCHAR(100), SubDescription VARCHAR(100));
  8.  
  9. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment', 'Peds' );
  10. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment', 'Peds2' );
  11. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment', 'Peds3' );
  12. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment', 'Peds4' );
  13.  
  14. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment1', 'Peds' );
  15. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment1', 'Peds2' );
  16. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment1', 'Peds3' );
  17. INSERT INTO #temp ( Description, SubDescription )VALUES ( 'Patient Assignment1', 'Peds4' );
  18.  
  19. WITH Temp
  20. AS (
  21. SELECT
  22. Description,
  23. SubDescription,
  24. ROW_NUMBER() OVER ( PARTITION BY Description
  25. ORDER BY Description ) rownumber
  26. FROM #Temp
  27. )
  28. SELECT
  29. CASE WHEN Temp.rownumber = 1 THEN Description ELSE '' END Description,
  30. SubDescription
  31. FROM Temp;
  32.  
  33. select C.Description,s.Description
  34. from category C
  35. inner join SubCategory S on C.CategoryID =S.CategoryID
  36. where C.IsActive=1 and S.IsActive=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement