Advertisement
ssmock

Untitled

Apr 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.36 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 FinancialSets
  55. where
  56.     StudentId = @studentId
  57.  
  58. delete StudentDisclaimerSignOffs
  59. where
  60.     StudentId = @studentId
  61.    
  62. update Students
  63. set
  64.     StudentProfileId = null
  65. where
  66.     UserName like @userName
  67.  
  68. delete StudentProfiles
  69. where
  70.     StudentId = @studentId
  71.  
  72. delete AcademicProfiles
  73. where
  74.     StudentId = @studentId
  75.  
  76. delete Students where UserName like @userName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement