Last active
July 19, 2016 07:12
-
-
Save hidayat365/9385116 to your computer and use it in GitHub Desktop.
Stored Procedure untuk encapsulate beberapa perintah SQL menjadi satu kesatuan.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- ------------------------- | |
| -- ini stored procedure-nya | |
| -- ------------------------- | |
| CREATE PROCEDURE InsertDataSMS | |
| @KodeKel int, | |
| @KodeTPS int, | |
| @SuaraPartai int, | |
| @KodeCaleg1 int = -1, | |
| @SuaraCaleg1 int = -1, | |
| @KodeCaleg2 int = -1, | |
| @SuaraCaleg2 int = -1 | |
| AS | |
| BEGIN | |
| SET NOCOUNT ON; | |
| -- suara partai | |
| UPDATE TPSSet SET SuaraPartai=@SuaraPartai | |
| WHERE TPS_Kelurahan = @KodeKel AND TPSS = @KodeTPS | |
| -- suara caleg 1 | |
| IF @KodeCaleg1 > 0 | |
| BEGIN | |
| UPDATE Calegs | |
| SET JumlahPerolehan=@SuaraCaleg1 | |
| WHERE Code = @KodeCaleg1 | |
| AND Caleg_TPS IN ( | |
| SELECT id FROM TPSSet | |
| WHERE TPS_Kelurahan = @KodeKel AND TPSS = @KodeTPS | |
| ) | |
| END | |
| -- suara caleg 2 | |
| IF @KodeCaleg1 > 0 | |
| BEGIN | |
| UPDATE Calegs | |
| SET JumlahPerolehan=@SuaraCaleg2 | |
| WHERE Code = @KodeCaleg2 | |
| AND Caleg_TPS IN ( | |
| SELECT id FROM TPSSet | |
| WHERE TPS_Kelurahan = @KodeKel AND TPSS = @KodeTPS | |
| ) | |
| END | |
| END | |
| GO | |
| -- --------------------- | |
| -- ini cara panggilnya | |
| -- --------------------- | |
| BEGIN TRANSACTION | |
| EXEC InsertDataSMS 1, 1,200, 1,200 | |
| EXEC InsertDataSMS 1, 2,300, 1,200, 2,100 | |
| COMMIT | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment