Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE @userId INT = (SELECT Id FROM Users
- WHERE Username = 'Alex')
- DECLARE @gameId INT = (SELECT Id FROM Games
- WHERE Name = 'Edinburgh')
- DECLARE @userGameId INT = (SELECT Id FROM UsersGames
- WHERE UserId = @userId AND GameId = @gameId)
- DECLARE @itemsSum DECIMAL(15, 2) = (
- select SUM(Price) from Items
- where Name in ('Blackguard', 'Bottomless Potion of Amplification',
- 'Eye of Etlich (Diablo III)', 'Gem of Efficacious Toxin',
- 'Golden Gorget of Leoric', 'Hellfire Amulet'))
- BEGIN TRY
- BEGIN TRANSACTION
- UPDATE UsersGames
- SET Cash -= @itemsSum
- WHERE Id = @userGameId
- INSERT INTO UserGameItems
- SELECT Id, @userGameId FROM Items
- WHERE Name in ('Blackguard', 'Bottomless Potion of Amplification',
- 'Eye of Etlich (Diablo III)', 'Gem of Efficacious Toxin',
- 'Golden Gorget of Leoric', 'Hellfire Amulet')
- COMMIT
- END TRY
- BEGIN CATCH
- ROLLBACK
- END CATCH
- SELECT u.Username, g.Name, ug.Cash, i.Name AS [Item Name]
- FROM UsersGames AS ug
- JOIN Games AS g ON ug.GameId = g.Id
- JOIN Users AS u ON ug.UserId = u.Id
- JOIN UserGameItems AS ugi ON ug.Id = ugi.UserGameId
- JOIN Items AS i ON i.Id = ugi.ItemId
- WHERE g.Name = 'Edinburgh'
Add Comment
Please, Sign In to add comment