MarkUa

Untitled

May 16th, 2019
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.70 KB | None | 0 0
  1. CREATE FUNCTION PlayerStatistic(@id int)
  2. RETURNS  @rtnTable TABLE
  3. (
  4.     -- columns returned by the function
  5.     home_team Varchar(30), guest_team Varchar(30),team_name Varchar(30),start_time Datetime,ganeral_game_time_goal_scored int default NULL,overtime_time_goal_scored int default NULL,after_total_time_bullit_scored int default NULL,
  6.     home_team_score int default NULL,overtime_home_team_score int default NULL,bullits_home_team_score int default NULL,guest_team_score int default NULL,overtime_guest_team_score int default NULL,bullits_guest_team_score int default NULL
  7. )
  8. AS
  9. BEGIN
  10. DECLARE @Table table (home_team Varchar(30), guest_team Varchar(30),  team_name Varchar(30),start_time Datetime, ganeral_game_time_goal_scored int,overtime_time_goal_scored int ,after_total_time_bullit_scored int,
  11.                     home_team_score int,overtime_home_team_score int,bullits_home_team_score int,guest_team_score int,overtime_guest_team_score int,bullits_guest_team_score int )
  12.  
  13. insert into @Table
  14. select (select Team.team_name from Team where Team.team_id = ga.home_team_id), (select Team.team_name from Team where Team.team_id = ga.guest_team_id), t.team_name,ga.start_time,  pl.ganeral_game_time_goal_scored,pl.overtime_goal_scored, pl.after_total_time_bullit_scored,
  15.        ga.home_team_score,ga.overtime_home_team_score,bullits_home_team_score, ga.guest_team_score, ga.overtime_guest_team_score,ga.bullits_guest_team_score
  16. from PlayerGameApplication pl
  17.     Join Game ga on pl.game_id = ga.game_id
  18.     Join Players player on player.player_id = pl.player_id
  19.     Join Team t on t.team_id = pl.team_id
  20.      where pl.player_id = @id
  21. --This select returns data
  22. insert into @rtnTable
  23. SELECT * FROM @Table
  24. return
  25. END;
Add Comment
Please, Sign In to add comment