-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add attempt at p1 solution, to test later
- Loading branch information
1 parent
2b6e2e6
commit e72d807
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Parameters: | ||
Return: INT | ||
Purpose: | ||
Detailed explanation of the function which includes: | ||
- Function business logic | ||
- Transformation rules | ||
- Here is a bit more text. | ||
*/ | ||
CREATE FUNCTION function_name () | ||
RETURNS INT | ||
AS | ||
BEGIN | ||
-- SQL statements to define the function logic | ||
CREATE TABLE IF NOT EXISTS threes ( value INT ); | ||
CREATE TABLE IF NOT EXISTS fives ( value INT ); | ||
CREATE TABLE IF NOT EXISTS fifteens ( value INT ); | ||
DECLARE @i INT = 0; | ||
|
||
WHILE @i < 1000; | ||
BEGIN | ||
SET @i = @i + 3; | ||
INSERT INTO threes VALUES ( @i ); | ||
END | ||
|
||
SET @i = 0; | ||
WHILE @i < 1000; | ||
BEGIN | ||
SET @i = @i + 5; | ||
INSERT INTO fives VALUES ( @i ); | ||
END | ||
|
||
DECLARE @result INT = SELECT SUM(value) FROM threes; | ||
SET @result = @result + SELECT SUM(value) FROM fives; | ||
SET @result = @result - SELECT SUM(value) FROM threes JOIN fives WHERE threes.value = fives.value; | ||
DELETE threes; | ||
DELETE fives; | ||
DELETE fifteens; | ||
RETURN @result; | ||
-- Return statement indicating the result of the function | ||
END; |