Guest User

Untitled

a guest
May 27th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. $DBServer="DBServ"
  2. $DB="DB"
  3. $Query_SQL="SELECT courseCode + staLName + CAST((FORMAT(schDateStart, 'yyyyMMdd')) AS VARCHAR) + rooRoom as PK,
  4. couTitle + '-' + SchSectionID + '-' + staLName + ' ' + CAST((FORMAT(schDateStart, 'yyyyMMdd')) AS VARCHAR) AS ID,
  5. couTitle AS CourseTitle,
  6. courseCode AS CourseCode,
  7. schSectionID AS SecID,
  8. schDateStart AS DateStart,
  9. schDateEnd AS DateEnd,
  10. schTimeStart AS TimeStart,
  11. schTimeEnd AS TimeEnd,
  12. schDaysOfWeek AS Days,
  13. schCourseStatus AS Status,
  14. schNotes AS Notes,
  15. rooRoom AS RoomNumber,
  16. facName AS Facility,
  17. staFName + ' ' + staLName AS Instructor,
  18. lastModified AS LastModified ,
  19. CustomSchedule AS Custom
  20. FROM VIEW
  21. ORDER BY schDateStart"
  22.  
  23.  
  24. $conn_SQL=New-Object system.data.sqlclient.sqlconnection("Server=$DBServer;Database=$DB;Integrated Security=True")
  25. $da_SQL=New-Object system.data.sqlclient.sqldataadapter($Query_SQL,$conn_SQL)
  26. $dt_SQL=New-Object system.data.datatable
  27.  
  28. #try the SQL connection if error then exit the script
  29. try
  30. {
  31. $conn_SQL.Open()
  32. [void]$da_SQL.fill($dt_SQL)
  33. $conn_SQL.Close()
  34. }
  35. catch
  36. {
  37. Write-Output "Error connecting to DB"
  38. exit
  39. }
  40.  
  41. $dt_SQL.primarykey=$dt_SQL.columns[0]
  42. $Sections=$dt_SQL.Rows
  43.  
  44. foreach($section in $Sections | Where-Object {$_.Custom -eq "true"})
  45. {
  46. if(($Sections | Where-Object {$_.secID -eq $section.SecID}).count -gt 1)
  47. {
  48. foreach($sec in $Sections | Where-Object {$_.secID -eq $section.SecID})
  49. {
  50. if($sec.LastModified -gt $lastUpdate)
  51. {
  52. foreach($sect in $Sections | Where-Object {$_.secID -eq $section.SecID})
  53. {
  54. $sect.LastModified = $sec.LastModified
  55. }
  56. }
  57. }
  58. }
  59. }
Add Comment
Please, Sign In to add comment