ssmock

Untitled

Apr 20th, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.54 KB | None | 0 0
  1. use VirtualTransferAdvisor
  2.  
  3. -- Change this user name (or pattern) to the one you want to delete
  4. declare @userName varchar(50) = 'host'
  5.  
  6. declare @studentId int
  7.  
  8. select @studentId = StudentId
  9. from
  10.     Students
  11. where
  12.     UserName = @userName
  13.  
  14. update FinancialSets
  15. set
  16.     YearlyStudentProfileId = null
  17. from
  18.     FinancialSets fs
  19. where
  20.     fs.StudentId = @studentId
  21.  
  22. delete YearlyStudentProfiles
  23. from
  24.     YearlyStudentProfiles ysp
  25.     join FinancialSets fs on
  26.         ysp.FinancialSetId = fs.FinancialSetId
  27. where
  28.     fs.StudentId = @studentId
  29.  
  30. delete FinancialFactors
  31. from
  32.     FinancialFactors ff
  33.     join FinancialSets fs on
  34.         ff.FinancialSetId = fs.FinancialSetId
  35. where
  36.     fs.StudentId = @studentId
  37.  
  38. delete InformationalFinancialFactors
  39. from
  40.     InformationalFinancialFactors iff
  41.     join FinancialSets fs on
  42.         iff.FinancialSetId = fs.FinancialSetId
  43. where
  44.     fs.StudentId = @studentId
  45.  
  46. delete StudentLoanPayoffs
  47. where
  48.     StudentId = @studentId
  49.  
  50. delete StudentMonthlyBudgets
  51. where
  52.     StudentId = @studentId
  53.  
  54. delete FinancialSetCompletionDetails
  55. from
  56.     FinancialSetCompletionDetails fscd
  57.     join FinancialSets fs on
  58.         fscd.FinancialSetId = fs.FinancialSetId
  59. where
  60.     fs.StudentId = @studentId
  61.  
  62. delete FinancialSets
  63. where
  64.     StudentId = @studentId
  65.  
  66. delete StudentDisclaimerSignOffs
  67. where
  68.     StudentId = @studentId
  69.    
  70. update Students
  71. set
  72.     StudentProfileId = null
  73. where
  74.     UserName like @userName
  75.  
  76. delete StudentProfiles
  77. where
  78.     StudentId = @studentId
  79.  
  80. delete AcademicProfiles
  81. where
  82.     StudentId = @studentId
  83.  
  84. delete Students where UserName like @userName
Add Comment
Please, Sign In to add comment