Guest User

Untitled

a guest
Nov 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. CREATE TABLE [dbo].[tbl_PitchLog]
  2. (
  3. [Id] BIGINT NOT NULL PRIMARY KEY IDENTITY,
  4. [At_Bat_ID] BIGINT NOT NULL,
  5. [Batter_ID] BIGINT NOT NULL,
  6. [Pitcher_ID] BIGINT NOT NULL,
  7. [Game_ID] BIGINT NOT NULL,
  8. [Season_ID] BIGINT NOT NULL,
  9. [Pitch_Type] VARCHAR(50) NULL,
  10. [Pitch_Speed] BIGINT NULL,
  11. [Pitch_X] BIGINT NULL,
  12. [Pitch_Y] BIGINT NULL,
  13. [Strike] BIT NULL,
  14. [Swung] BIT NULL,
  15. [Contact] BIT NULL,
  16. [Fair] BIT NULL,
  17. [R] BIT NULL,
  18. [H] BIT NULL,
  19. [1B] BIT NULL,
  20. [2B] BIT NULL,
  21. [3B] BIT NULL,
  22. [HR] BIT NULL,
  23. [RBI] INT NULL,
  24. [BB] BIT NULL,
  25. [SO] BIT NULL,
  26. [IBB] BIT NULL,
  27. [HBP] BIT NULL,
  28. [SH] BIT NULL,
  29. [SF] BIT NULL,
  30. [GIDP] BIT NULL
  31. )
  32.  
  33. GO
  34.  
  35. CREATE TRIGGER [dbo].[Trigger_tbl_PitchLog]
  36. ON [dbo].[tbl_PitchLog]
  37. FOR DELETE, INSERT, UPDATE
  38. AS
  39. DECLARE @Strikes integer, @Balls integer
  40. DECLARE @Fouls integer
  41. DECLARE @Contact integer
  42. IF Strike = 1
  43. BEGIN
  44. SET @Strikes = 1;
  45. SET @Balls = 0;
  46. END
  47. ELSE
  48. BEGIN
  49. SET @Strikes = 0;
  50. SET @Balls = 1;
  51. END
  52. IF Fair = 0
  53. BEGIN
  54. SET @Fouls = 1;
  55. END
  56. ELSE
  57. BEGIN
  58. SET @Fouls = 0;
  59. END
  60. IF Contact = 0
  61. BEGIN
  62. SET @Contact = 1;
  63. END
  64. ELSE
  65. BEGIN
  66. SET @Contact = 0;
  67. END
  68. BEGIN
  69. SET NoCount ON
  70. UPDATE tbl_AtBats
  71. SET tbl_AtBats.PitchCount = tbl_AtBats.PitchCount + 1,
  72. tbl_AtBats.Strikes = tbl_AtBats.Strikes + @Strikes,
  73. tbl_AtBats.Balls = tbl_AtBats.Balls + @Balls,
  74. tbl_AtBats.Fouls = tbl_AtBats.Fouls + @Fouls,
  75. tbl_AtBats.Contact = tbl_AtBats.Contact + @Contact,
  76. tbl_AtBats.Swings = tbl_AtBats.Swings + inserted.Swung,
  77. tbl_AtBats.R = inserted.R,
  78. tbl_AtBats.H = inserted.H,
  79. tbl_AtBats.[1B] = inserted.[1B],
  80. tbl_AtBats.[2B] = inserted.[2B],
  81. tbl_AtBats.[3B] = inserted.[3B],
  82. tbl_AtBats.HR = inserted.HR,
  83. tbl_AtBats.RBI = inserted.RBI,
  84. tbl_AtBats.BB = inserted.BB,
  85. tbl_AtBats.SO = inserted.SO,
  86. tbl_AtBats.IBB = inserted.IBB,
  87. tbl_AtBats.HBP = inserted.HBP,
  88. tbl_AtBats.SH = inserted.SH,
  89. tbl_AtBats.SF = inserted.SF,
  90. tbl_AtBats.GIDP = inserted.GIDP
  91. WHERE tbl_AtBats.Id = inserted.At_Bat_ID;
  92. END
Add Comment
Please, Sign In to add comment