Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. USE STG_RM_Connector
  2. GO
  3.  
  4. DECLARE @tblAttCode sysname, @tblAttSess sysname, @tblStaffServ sysname, @tblStuSer sysname
  5. DECLARE @rowCntAttCode int, @rowCntAttSess int, @rowCntStaffServ int, @rowCntStuSer int
  6.  
  7. SET @tblAttSess = 'Attendance Session Pupil Data'
  8. SET @tblAttCode = 'Attendace Code Service Attendace Codes'
  9. SET @tblStaffServ = 'Staff Service Staff Members'
  10. SET @tblStuSer = 'Student Service Pupil Data'
  11.  
  12. SELECT @rowCntAttCode = SUM(PART.rows)
  13. FROM sys.tables TBL
  14. INNER JOIN sys.partitions PART ON TBL.object_id = PART.object_id
  15. INNER JOIN sys.indexes IDX ON PART.object_id = IDX.object_id
  16. AND PART.index_id = IDX.index_id
  17. WHERE TBL.name = @tblAttCode
  18. AND IDX.index_id < 2
  19. GROUP BY TBL.object_id, TBL.name;
  20.  
  21. SELECT @rowCntAttSess = SUM(PART.rows)
  22. FROM sys.tables TBL
  23. INNER JOIN sys.partitions PART ON TBL.object_id = PART.object_id
  24. INNER JOIN sys.indexes IDX ON PART.object_id = IDX.object_id
  25. AND PART.index_id = IDX.index_id
  26. WHERE TBL.name = @tblAttSess
  27. AND IDX.index_id < 2
  28. GROUP BY TBL.object_id, TBL.name;
  29.  
  30. SELECT @rowCntStaffServ = SUM(PART.rows)
  31. FROM sys.tables TBL
  32. INNER JOIN sys.partitions PART ON TBL.object_id = PART.object_id
  33. INNER JOIN sys.indexes IDX ON PART.object_id = IDX.object_id
  34. AND PART.index_id = IDX.index_id
  35. WHERE TBL.name = @tblStaffServ
  36. AND IDX.index_id < 2
  37. GROUP BY TBL.object_id, TBL.name;
  38.  
  39. SELECT @rowCntStuSer = SUM(PART.rows)
  40. FROM sys.tables TBL
  41. INNER JOIN sys.partitions PART ON TBL.object_id = PART.object_id
  42. INNER JOIN sys.indexes IDX ON PART.object_id = IDX.object_id
  43. AND PART.index_id = IDX.index_id
  44. WHERE TBL.name = @tblStuSer
  45. AND IDX.index_id < 2
  46. GROUP BY TBL.object_id, TBL.name;
  47.  
  48. IF @rowCntAttCode = 0 AND @rowCntAttSess = 0 AND @rowCntStaffServ = 0 AND @rowCntStuSer = 0
  49. BEGIN
  50. RAISERROR ('Failed to pull data for all tables', 16, 1)
  51. END
  52. ELSE IF @rowCntAttCode = 0 OR @rowCntAttSess = 0 OR @rowCntStaffServ = 0 OR @rowCntStuSer = 0
  53. BEGIN
  54. RAISERROR ('Failed to pull data for one of the RM staging tables', 10, 1)
  55. END
  56. ELSE
  57. BEGIN
  58. PRINT 'Successfully pulled data for all RM staging tables'
  59. END
  60. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement