SlideShare a Scribd company logo
1 of 17
Final Project
Be sure to follow the instructions for each step as you will be
graded accordingly. Each report should have a title and
appropriate field headings for each column of data. If you list a
team or player always list both the number and name. Be sure
that your results are sorted as requested, and that your numbers
make sense. Make all of your reports stored procedures, I will
want a copy of each stored procedure, and your results which
will be a query that runs all of them and the output they
produce.
1. Produce a list of Teams including how many points they
earned (determine this in a function that takes each team as its
being read in and brings back the number of points) sort the
output in highest to lowest order according to the points they
received and create an additional column that designates who
came in 1st place, 2nd place, and 3rd place. Include the name
of the manager in your list.
2. Produce a list of Players, by Team, with a blank line in
between each teams players. Include their starting average, and
the average of what they bowled during the league (do this by
building a function that you can call from your stored procedure
that will take the current player being read by your procedure
and determine his average for the league play) the results
should be sorted numerically in team and player order. At the
bottom of the report list : Which player bowled the highest
average during the league, and which was the most improved
from his starting average, be sure to label this output
appropriately.
3. Produce a list that shows week by week which teams played
which, and the points they earned that particular week. Sort the
output in week order and then by team number 1 order (you are
using the schedule table as your driver for this) make sure to
skip a line in between each weeks output.
Make sure all stored procedures and functions use your Team
Number as part of their name
Advanced SQL – Week 13
Triggers are SQL statements that are automatically executed
when certain events occur. They can be tied to the following
statements: DELETE, INSERT, and UPDATE.
For example you might save a copy of a row in an archive table
before issuing a DELETE statement. Check that certain fields
are formatted correctly before doing an INSERT, or perform
calculations such as subtracting the order quantity from the
amount on hand when doing an UPDATE
Each of the above examples have in common that something
needs to be done automatically whenever a change occurs to a
table.
Triggers can be single statements, or groups of statements that
are enclosed within a BEGIN and END statement.
You create a trigger by supplying 3 pieces of information: a
unique trigger name, the table it is to be associated with, and
the event that should trigger it.
CREATE TRIGGER process_scores ON scores AFTER INSERT
AS
SELECT ‘Another score has been added’;
Triggers are defined per event per table, and only one trigger
per event per table is allowed. So you cannot have more than 3
triggers per table (one for INSERT, UPDATE, and DELETE)
You can also define a trigger as AFTER INSERT, UPDATE so
that the same trigger will happen with two different events
You can DROP TRIGGER process_scores and you can ALTER
TRIGGER process_scores
There is also a INSTEAD OF trigger that replaces a given
command with another action. So instead of deleting records it
might mark them as inactive.
You can DISABLE TRIGGER process_scores ON scores and
you can ENABLE TRIGGER process_scores ON scores
Triggers are often used to create audit logs and can call Stored
Procedures.
Within INSERT trigger code, you can refer to a virtual table
named INSERTED to access the rows being inserted.
Within DELETE trigger code, you can refer to a virtual table
named DELETED to access the rows being deleted.
Within UPDATE trigger code, you can refer to a virtual table
named DELETED to access the previous (pre-UPDATE
statement) values and INSERTED to access the new updated
values.
The fact that triggers alter the apparent functioning of SQL as
they operate invisibly becomes an issue that must be identified
and dealt with.
ALWAYS check the tables that you are planning to access to
determine what is hiding such as keys and triggers. Knowing
what functions and stored procedures have been written can
assist you in your programming, as can being aware of views
and indexes.
Advanced SQL – Week 12
DECLARE Defines a new cursor.
OPEN Opens and populates the cursor by executing the
SELECT statement defined by the cursor.
FETCH Retrieves a row from the cursor.
CLOSE Closes the cursor.
DEALLOCATE Deletes the cursor definition and releases all
system resources associated with the cursor.
-- Step 1 Define any variable you intend to use
DECLARE @AccountID INT
DECLARE @getAccountID CURSOR
-- Step 2 Write your query and stick the results in the cursor
SET @getAccountID = CURSOR FOR
SELECT EMPNO
FROM EMP
-- Step 3 Open the cursor and read the first record
OPEN @getAccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
-- Step 4 Loop through the cursor reading each line until they
are no more
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @AccountID
FETCH NEXT
FROM @getAccountID INTO @AccountID
END
-- Step 5 Close the cursor and clear the memory it used
CLOSE @getAccountID
DEALLOCATE @getAccountID
http://www.kodyaz.com/articles/cursor.aspx
http://msdn.microsoft.com/en-us/library/ms180169.aspx
http://www.kodyaz.com/articles/t-sql-cursor-example-code.aspx
http://msdn.microsoft.com/en-
us/library/aa172595(SQL.80).aspx
These are important for the homework
http://www.eggheadcafe.com/software/aspnet/31208449/multipl
e-rows-into-multiple-columns.aspx
http://www.sqlteam.com/article/cursors-an-overview
HOMEWORK
1) Modify todays example to print the employee number and
name. I want you to print the employee number such that odd
numbers are to the left and even numbers are to the right.
12311 John Doe
12312 Jane Smith
2) Using the Bowling League Database. Produce a list of the
players on each team in team and player number order such that
you skip a blank line in between the list for each team. Show
the Team number and name and the player number and name.
Hints for Homework Week 11
--Step 1 Create a table of Agregated Scores by Date_Bowled,
Team_ID, Team_Name in a temporary file
--Step 2 Use the schedule and the table you created in Step 1 (2
times) to align the team information onto one row for both
teams in a temporary file (Hint: you should not be calculating
anything here just joining two vertical records from step 1 into
1 horizontal record)
--Step 3 Use the table you created in Step 2 to assign the points,
remember to code for ties and put the results into a temporary
file (Hint: your records are still horizontal here)
--Step 4 Build points table for all weeks and teams into a
temporary table that you will use for futher assignments (Hint:
you want your records to be vertical here now that the points
are calculated)
Drop
Table Schedule
create
table Schedule
(
Date_Bowled Date
,Team1 VARCHAR(2)
,Team2 VARCHAR(2)
);
GO
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','1','2');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','3','4');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','5','6');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','7','8');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','9','10');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','11','12');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','13','14');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/10/15','15','17');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','1','3');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','2','4');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','5','7');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','6','8');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','9','12');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','10','11');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','13','17');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/17/15','14','15');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','1','4');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','2','3');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','5','8');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','6','7');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','9','11');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','10','12');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','13','15');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/24/15','14','17');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','1','5');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','2','6');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','3','7');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','4','8');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','9','13');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','10','14');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','11','15');
INSERT
INTO Schedule (Date_Bowled, Team1, Team2)
VALUES('01/31/15','12','17');
INSERT
INTO
...
Sheet1Date_BowledTeam1Team201/10/151201/10/153401/10/1
55601/10/157801/10/1591001/10/15111201/10/15131401/10/151
51701/17/151301/17/152401/17/155701/17/156801/17/1591201/
17/15101101/17/15131701/17/15141501/24/151401/24/152301/2
4/155801/24/156701/24/1591101/24/15101201/24/15131501/24/
15141701/31/151501/31/152601/31/153701/31/154801/31/15913
01/31/15101401/31/15111501/31/15121702/07/151602/07/15270
2/07/153802/07/154502/07/1591402/07/15101502/07/15111702/
07/15121302/14/151702/14/152802/14/153502/14/154602/14/15
91502/14/15101702/14/15111302/14/15121402/21/151802/21/15
2502/21/153602/21/154702/21/1591702/21/15101302/21/151114
02/21/15121502/28/151902/28/1521002/28/1531102/28/1541202
/28/1551302/28/1561402/28/1571502/28/1581703/07/1511003/0
7/1521103/07/1531203/07/1541303/07/1551403/07/1561503/07/
1571703/07/158903/14/1511103/14/1521203/14/1531303/14/154
1403/14/1551503/14/1561703/14/157903/14/1581003/21/151120
3/21/1521303/21/1531403/21/1541503/21/1551703/21/156903/2
1/1571003/21/1581103/28/1511303/28/1521403/28/1531503/28/
1541703/28/155903/28/1561003/28/1571103/28/1581204/04/151
1404/04/1521504/04/1531704/04/154904/04/1551004/04/156110
4/04/1571204/04/1581304/11/1511504/11/1521704/11/153904/1
1/1541004/11/1551104/11/1561204/11/1571304/11/1581404/18/
1511704/18/152904/18/1531004/18/1541104/18/1551204/18/156
1304/18/1571404/18/15815
CASE WHEN TEAM1_GAME1>TEAM2_GAME1 THEN 1
ELSE 0 END GAME1,
if 12 % 2 =0
PRINT cast( 12 as char(4)) + ' '+'right'
if 13 % 2 <>0
PRINT cast( 13 as char(4))+ ' '+'left'
WHILE @@FETCH_STATUS=0
BEGIN
IF @STUDENT<>@TEMP_STUDENT
PRINT ''
PRINT @STUDENT
SELECT @[email protected]
FETCH NEXT
New Homework
Delete scores for Week16 and Week17
Create a schedule table in your bowling database to store the
attached list. Be careful that the fields you create have the
same datatype and length and the equivalent fields in the scores
table.
Now the fun begins. Create a script that uses the schedule to
read the scores table and produce a list that shows: HINT - You
have to use the scores table twice in your query, once to link
Team 1 for any given week and once to link Team 2 for any
given week.
Date, Team1 Number and Name, Total score for Game1, Game
2, Game 3 and Series and Team2 Number and Name, Total score
for Game1, Game 2, Game 3 and Series .
You also need to determine how many points each of the teams
earned, they get 1 point for having the highest team score for
Game 1, Game 2, Game 3, and Series. (So each match up
should produce 4 points divided among the two teams.)
Make the list in date and Team1 Number order.
At the end list a summary of each team and how many points
they earned using variables. There will be 480 points in total
for the 15 weeks we bowled.
Advanced SQL – Week 11
· The USE statement sets the current database
· You must DECLARE variables before you use them, you can
define one or more at the same time.
DECLARE @variablename variabletype = value
SET @TotalCost = 10
SET @TotalCost = @UnitCost * 1.1
DECLARE @Test money
SET @Test = (SELECT MAX(Sal) FROM Emp)
SELECT @Test
PRINT 'The maximum salary is ' +CONVERT(varchar,@Test,1)
go
· There are a number of System Variables such as: @@ERROR,
@@IDENTITY, @@ROWCOUNT
· To separate a script into multiple batches, we use the GO
statement. Using it causes all statements ince the beginning of
the script or the last GO statement (whichever is closer) to be
compiled into one execution plan and sent to the server
independently of any other batches.
· Variables declared in one batch are not available to other
batches
EXAMPLES
SELECT convert(varchar,table_catalog,20) as "Database
Name", table_name
FROM information_schema.tables
create table Billings (
BankerID INTEGER,
BillingNumber INTEGER,
BillingDate datetime,
BillingTotal INTEGER,
TermsID INTEGER,
BillingDueDate datetime ,
PaymentTotal INTEGER,
CreditTotal INTEGER);
GO
INSERT INTO Billings VALUES (5, 1, '2005-01-22', 110,
1,'2005-04-22',123,321);
GO
INSERT INTO Billings VALUES (2, 2, '2001-02-21', 165,
1,'2002-02-22',123,321.);
GO
INSERT INTO Billings VALUES (5, 3, '2003-05-02', 190,
1,'2005-04-12',123,321);
GO
INSERT INTO Billings VALUES (4, 4, '1999-03-12', 165,
1,'2005-04-18',123,321);
GO
INSERT INTO Billings VALUES (5, 5, '2000-04-23', 165,
1,'2005-04-17',123,321);
GO
INSERT INTO Billings VALUES (6, 6, '2001-06-14', 165,
1,'2005-04-18',123,321);
GO
INSERT INTO Billings VALUES (5, 7, '2002-07-15', 120,
1,'2005-04-19',123,321);
GO
INSERT INTO Billings VALUES (8, 8, '2003-08-16', 165,
1,'2005-04-20',123,321);
GO
INSERT INTO Billings VALUES (9, 9, '2004-09-17', 165,
1,'2005-04-21',123,321);
GO
INSERT INTO Billings VALUES (5, 0, '2005-10-18', 145,
1,'2005-04-22',123,321);
GO
DECLARE @MaxBilling money, @MinBilling money
DECLARE @PercentDifference decimal(8,2)
DECLARE @BillingCount int, @BankerIDVar int
SET @BankerIDVar = 5
SET @MaxBilling = (SELECT MAX(BillingTotal) FROM
Billings
WHERE BankerID = @BankerIDVar)
SELECT @MinBilling = MIN(BillingTotal), @BillingCount =
COUNT(*)
FROM Billings
WHERE BankerID = @BankerIDVar
SET @PercentDifference = (@MaxBilling - @MinBilling) /
@MinBilling * 100
PRINT 'Maximum Billing is $' +
CONVERT(varchar,@MaxBilling,1) + '.'
PRINT 'Minimum Billing is $' +
CONVERT(varchar,@MinBilling,1) + '.'
PRINT 'Maximum is ' +
CONVERT(varchar,@PercentDifference) +
'% more than minimum.'
PRINT 'Number of Billings: ' +
CONVERT(varchar,@BillingCount) + '.'
· Control of Flow Statements: IF … ELSE, CASE, WHILE
IF <Boolean Expression>
<SQL statement> | BEGIN <code series> END
[ELSE
<SQL statement> | BEGIN <code series> END]
Variable = CASE <input expression>
WHEN <when expression> THEN <result expression>
[…n]
[ELSE <result expression>]
END
WHILE <Boolean expression>
<sql statement> |
[BEGIN
<statement block>
[BREAK]
<sql statement> | <statement block>
[CONTINUE]
Transact-SQL Variableshttp://msdn.microsoft.com/en-
us/library/ms187953.aspx
T-SQL Loop Statement
http://www.databasejournal.com/features/mssql/article.php/3100
621/T-SQL-Programming-Part-2---Building-a-T-SQL-Loop.htm
Looping Statements
http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?t
opic=/com.ibm.db2.udb.apdv.sql.doc/doc/c0024350.htm
Final ProjectBe sure to follow the instructions for each step as.docx

More Related Content

Similar to Final ProjectBe sure to follow the instructions for each step as.docx

Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql databaseKimera Richard
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planMaria Colgan
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005rainynovember12
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxCliffordBorromeo
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsNirav Shah
 
9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptxSheryldeVilla2
 
Mysqlppt
MysqlpptMysqlppt
MysqlpptReka
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptxTadiwaMawere
 
Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Jean-Marc Desvaux
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Thuan Nguyen
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
Management of database information system
Management of database information systemManagement of database information system
Management of database information systemKAZEMBETVOnline
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain PlanMaria Colgan
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Thuan Nguyen
 

Similar to Final ProjectBe sure to follow the instructions for each step as.docx (20)

Excel_Tips
Excel_TipsExcel_Tips
Excel_Tips
 
Unit 2 web technologies
Unit 2 web technologiesUnit 2 web technologies
Unit 2 web technologies
 
Triggers
TriggersTriggers
Triggers
 
Pl sql using_xml
Pl sql using_xmlPl sql using_xml
Pl sql using_xml
 
Using triggers in my sql database
Using triggers in my sql databaseUsing triggers in my sql database
Using triggers in my sql database
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_plan
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
Advanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptxAdvanced Spreadsheet Skills-1.pptx
Advanced Spreadsheet Skills-1.pptx
 
Correlated update vs merge
Correlated update vs mergeCorrelated update vs merge
Correlated update vs merge
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
 
Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Web Developer make the most out of your Database !
Web Developer make the most out of your Database !
 
Excel Tips
Excel TipsExcel Tips
Excel Tips
 
Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17Oracle - Program with PL/SQL - Lession 17
Oracle - Program with PL/SQL - Lession 17
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Management of database information system
Management of database information systemManagement of database information system
Management of database information system
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
 
Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16Oracle - Program with PL/SQL - Lession 16
Oracle - Program with PL/SQL - Lession 16
 

More from voversbyobersby

Cost and benefit analysisWe are doing group presentation.docx
Cost and benefit analysisWe are doing group presentation.docxCost and benefit analysisWe are doing group presentation.docx
Cost and benefit analysisWe are doing group presentation.docxvoversbyobersby
 
Cosmetics as endocrine disruptors are they a health risk.docx
Cosmetics as endocrine disruptors are they a health risk.docxCosmetics as endocrine disruptors are they a health risk.docx
Cosmetics as endocrine disruptors are they a health risk.docxvoversbyobersby
 
COSC2737 Assignment 2 IT Infrastructure in the Cloud. .docx
COSC2737 Assignment 2  IT Infrastructure in the Cloud.  .docxCOSC2737 Assignment 2  IT Infrastructure in the Cloud.  .docx
COSC2737 Assignment 2 IT Infrastructure in the Cloud. .docxvoversbyobersby
 
Cortes and the Aztecs Respond in writing to the following questi.docx
Cortes and the Aztecs Respond in writing to the following questi.docxCortes and the Aztecs Respond in writing to the following questi.docx
Cortes and the Aztecs Respond in writing to the following questi.docxvoversbyobersby
 
Correlation and RegressionForecasting is a critical job for mana.docx
Correlation and RegressionForecasting is a critical job for mana.docxCorrelation and RegressionForecasting is a critical job for mana.docx
Correlation and RegressionForecasting is a critical job for mana.docxvoversbyobersby
 
Correlation and Regression StudyBackground During this week .docx
Correlation and Regression StudyBackground During this week .docxCorrelation and Regression StudyBackground During this week .docx
Correlation and Regression StudyBackground During this week .docxvoversbyobersby
 
Correlate your job responsibilities with the Disaster recovery c.docx
Correlate your job responsibilities with the Disaster recovery c.docxCorrelate your job responsibilities with the Disaster recovery c.docx
Correlate your job responsibilities with the Disaster recovery c.docxvoversbyobersby
 
Correctional CounselingRobert HanserScott Mire20111 The .docx
Correctional CounselingRobert HanserScott Mire20111 The .docxCorrectional CounselingRobert HanserScott Mire20111 The .docx
Correctional CounselingRobert HanserScott Mire20111 The .docxvoversbyobersby
 
Correlate health and safety issues at workplace with ideals. Y.docx
Correlate health and safety issues at workplace with ideals. Y.docxCorrelate health and safety issues at workplace with ideals. Y.docx
Correlate health and safety issues at workplace with ideals. Y.docxvoversbyobersby
 
Correctional Program ShowcaseSubmitted BY Intensive moti.docx
Correctional Program ShowcaseSubmitted BY Intensive moti.docxCorrectional Program ShowcaseSubmitted BY Intensive moti.docx
Correctional Program ShowcaseSubmitted BY Intensive moti.docxvoversbyobersby
 
Corrections in America - please type the answers separateDiscu.docx
Corrections in America - please type the answers separateDiscu.docxCorrections in America - please type the answers separateDiscu.docx
Corrections in America - please type the answers separateDiscu.docxvoversbyobersby
 
Correction to be made for my code of ethical plan Inclusion of.docx
Correction to be made for my code of ethical plan Inclusion of.docxCorrection to be made for my code of ethical plan Inclusion of.docx
Correction to be made for my code of ethical plan Inclusion of.docxvoversbyobersby
 
Correct the following paragraph. Insert or delete hyphens as nee.docx
Correct the following paragraph. Insert or delete hyphens as nee.docxCorrect the following paragraph. Insert or delete hyphens as nee.docx
Correct the following paragraph. Insert or delete hyphens as nee.docxvoversbyobersby
 
Correctional AdministratorsPrisons and jails are both clas.docx
Correctional AdministratorsPrisons and jails are both clas.docxCorrectional AdministratorsPrisons and jails are both clas.docx
Correctional AdministratorsPrisons and jails are both clas.docxvoversbyobersby
 
Corporations are making the assumption that everyone uses a sm.docx
Corporations are making the assumption that everyone uses a sm.docxCorporations are making the assumption that everyone uses a sm.docx
Corporations are making the assumption that everyone uses a sm.docxvoversbyobersby
 
Corporation M, a calendar year corporation that began doing business.docx
Corporation M, a calendar year corporation that began doing business.docxCorporation M, a calendar year corporation that began doing business.docx
Corporation M, a calendar year corporation that began doing business.docxvoversbyobersby
 
Corporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docx
Corporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docxCorporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docx
Corporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docxvoversbyobersby
 
CORPORATE TRAINING .docx
CORPORATE TRAINING                                            .docxCORPORATE TRAINING                                            .docx
CORPORATE TRAINING .docxvoversbyobersby
 
Corporate TAX homework problems. Need help with solving. email is .docx
Corporate TAX homework problems. Need help with solving. email is .docxCorporate TAX homework problems. Need help with solving. email is .docx
Corporate TAX homework problems. Need help with solving. email is .docxvoversbyobersby
 
Corporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docx
Corporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docxCorporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docx
Corporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docxvoversbyobersby
 

More from voversbyobersby (20)

Cost and benefit analysisWe are doing group presentation.docx
Cost and benefit analysisWe are doing group presentation.docxCost and benefit analysisWe are doing group presentation.docx
Cost and benefit analysisWe are doing group presentation.docx
 
Cosmetics as endocrine disruptors are they a health risk.docx
Cosmetics as endocrine disruptors are they a health risk.docxCosmetics as endocrine disruptors are they a health risk.docx
Cosmetics as endocrine disruptors are they a health risk.docx
 
COSC2737 Assignment 2 IT Infrastructure in the Cloud. .docx
COSC2737 Assignment 2  IT Infrastructure in the Cloud.  .docxCOSC2737 Assignment 2  IT Infrastructure in the Cloud.  .docx
COSC2737 Assignment 2 IT Infrastructure in the Cloud. .docx
 
Cortes and the Aztecs Respond in writing to the following questi.docx
Cortes and the Aztecs Respond in writing to the following questi.docxCortes and the Aztecs Respond in writing to the following questi.docx
Cortes and the Aztecs Respond in writing to the following questi.docx
 
Correlation and RegressionForecasting is a critical job for mana.docx
Correlation and RegressionForecasting is a critical job for mana.docxCorrelation and RegressionForecasting is a critical job for mana.docx
Correlation and RegressionForecasting is a critical job for mana.docx
 
Correlation and Regression StudyBackground During this week .docx
Correlation and Regression StudyBackground During this week .docxCorrelation and Regression StudyBackground During this week .docx
Correlation and Regression StudyBackground During this week .docx
 
Correlate your job responsibilities with the Disaster recovery c.docx
Correlate your job responsibilities with the Disaster recovery c.docxCorrelate your job responsibilities with the Disaster recovery c.docx
Correlate your job responsibilities with the Disaster recovery c.docx
 
Correctional CounselingRobert HanserScott Mire20111 The .docx
Correctional CounselingRobert HanserScott Mire20111 The .docxCorrectional CounselingRobert HanserScott Mire20111 The .docx
Correctional CounselingRobert HanserScott Mire20111 The .docx
 
Correlate health and safety issues at workplace with ideals. Y.docx
Correlate health and safety issues at workplace with ideals. Y.docxCorrelate health and safety issues at workplace with ideals. Y.docx
Correlate health and safety issues at workplace with ideals. Y.docx
 
Correctional Program ShowcaseSubmitted BY Intensive moti.docx
Correctional Program ShowcaseSubmitted BY Intensive moti.docxCorrectional Program ShowcaseSubmitted BY Intensive moti.docx
Correctional Program ShowcaseSubmitted BY Intensive moti.docx
 
Corrections in America - please type the answers separateDiscu.docx
Corrections in America - please type the answers separateDiscu.docxCorrections in America - please type the answers separateDiscu.docx
Corrections in America - please type the answers separateDiscu.docx
 
Correction to be made for my code of ethical plan Inclusion of.docx
Correction to be made for my code of ethical plan Inclusion of.docxCorrection to be made for my code of ethical plan Inclusion of.docx
Correction to be made for my code of ethical plan Inclusion of.docx
 
Correct the following paragraph. Insert or delete hyphens as nee.docx
Correct the following paragraph. Insert or delete hyphens as nee.docxCorrect the following paragraph. Insert or delete hyphens as nee.docx
Correct the following paragraph. Insert or delete hyphens as nee.docx
 
Correctional AdministratorsPrisons and jails are both clas.docx
Correctional AdministratorsPrisons and jails are both clas.docxCorrectional AdministratorsPrisons and jails are both clas.docx
Correctional AdministratorsPrisons and jails are both clas.docx
 
Corporations are making the assumption that everyone uses a sm.docx
Corporations are making the assumption that everyone uses a sm.docxCorporations are making the assumption that everyone uses a sm.docx
Corporations are making the assumption that everyone uses a sm.docx
 
Corporation M, a calendar year corporation that began doing business.docx
Corporation M, a calendar year corporation that began doing business.docxCorporation M, a calendar year corporation that began doing business.docx
Corporation M, a calendar year corporation that began doing business.docx
 
Corporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docx
Corporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docxCorporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docx
Corporate Valuation and Stock ValuationCHAPTER 7© 2020 Cenga.docx
 
CORPORATE TRAINING .docx
CORPORATE TRAINING                                            .docxCORPORATE TRAINING                                            .docx
CORPORATE TRAINING .docx
 
Corporate TAX homework problems. Need help with solving. email is .docx
Corporate TAX homework problems. Need help with solving. email is .docxCorporate TAX homework problems. Need help with solving. email is .docx
Corporate TAX homework problems. Need help with solving. email is .docx
 
Corporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docx
Corporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docxCorporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docx
Corporate Valuation and Financial PlanningCHAPTER 12© 2020 C.docx
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

Final ProjectBe sure to follow the instructions for each step as.docx

  • 1. Final Project Be sure to follow the instructions for each step as you will be graded accordingly. Each report should have a title and appropriate field headings for each column of data. If you list a team or player always list both the number and name. Be sure that your results are sorted as requested, and that your numbers make sense. Make all of your reports stored procedures, I will want a copy of each stored procedure, and your results which will be a query that runs all of them and the output they produce. 1. Produce a list of Teams including how many points they earned (determine this in a function that takes each team as its being read in and brings back the number of points) sort the output in highest to lowest order according to the points they received and create an additional column that designates who came in 1st place, 2nd place, and 3rd place. Include the name of the manager in your list. 2. Produce a list of Players, by Team, with a blank line in between each teams players. Include their starting average, and the average of what they bowled during the league (do this by building a function that you can call from your stored procedure that will take the current player being read by your procedure and determine his average for the league play) the results should be sorted numerically in team and player order. At the bottom of the report list : Which player bowled the highest average during the league, and which was the most improved from his starting average, be sure to label this output appropriately. 3. Produce a list that shows week by week which teams played which, and the points they earned that particular week. Sort the
  • 2. output in week order and then by team number 1 order (you are using the schedule table as your driver for this) make sure to skip a line in between each weeks output. Make sure all stored procedures and functions use your Team Number as part of their name Advanced SQL – Week 13 Triggers are SQL statements that are automatically executed when certain events occur. They can be tied to the following statements: DELETE, INSERT, and UPDATE. For example you might save a copy of a row in an archive table before issuing a DELETE statement. Check that certain fields are formatted correctly before doing an INSERT, or perform calculations such as subtracting the order quantity from the amount on hand when doing an UPDATE Each of the above examples have in common that something needs to be done automatically whenever a change occurs to a table. Triggers can be single statements, or groups of statements that are enclosed within a BEGIN and END statement. You create a trigger by supplying 3 pieces of information: a unique trigger name, the table it is to be associated with, and
  • 3. the event that should trigger it. CREATE TRIGGER process_scores ON scores AFTER INSERT AS SELECT ‘Another score has been added’; Triggers are defined per event per table, and only one trigger per event per table is allowed. So you cannot have more than 3 triggers per table (one for INSERT, UPDATE, and DELETE) You can also define a trigger as AFTER INSERT, UPDATE so that the same trigger will happen with two different events You can DROP TRIGGER process_scores and you can ALTER TRIGGER process_scores There is also a INSTEAD OF trigger that replaces a given command with another action. So instead of deleting records it might mark them as inactive. You can DISABLE TRIGGER process_scores ON scores and you can ENABLE TRIGGER process_scores ON scores Triggers are often used to create audit logs and can call Stored Procedures. Within INSERT trigger code, you can refer to a virtual table named INSERTED to access the rows being inserted. Within DELETE trigger code, you can refer to a virtual table named DELETED to access the rows being deleted. Within UPDATE trigger code, you can refer to a virtual table named DELETED to access the previous (pre-UPDATE statement) values and INSERTED to access the new updated values.
  • 4. The fact that triggers alter the apparent functioning of SQL as they operate invisibly becomes an issue that must be identified and dealt with. ALWAYS check the tables that you are planning to access to determine what is hiding such as keys and triggers. Knowing what functions and stored procedures have been written can assist you in your programming, as can being aware of views and indexes. Advanced SQL – Week 12 DECLARE Defines a new cursor. OPEN Opens and populates the cursor by executing the SELECT statement defined by the cursor. FETCH Retrieves a row from the cursor. CLOSE Closes the cursor. DEALLOCATE Deletes the cursor definition and releases all system resources associated with the cursor. -- Step 1 Define any variable you intend to use DECLARE @AccountID INT DECLARE @getAccountID CURSOR -- Step 2 Write your query and stick the results in the cursor SET @getAccountID = CURSOR FOR SELECT EMPNO FROM EMP -- Step 3 Open the cursor and read the first record
  • 5. OPEN @getAccountID FETCH NEXT FROM @getAccountID INTO @AccountID -- Step 4 Loop through the cursor reading each line until they are no more WHILE @@FETCH_STATUS = 0 BEGIN PRINT @AccountID FETCH NEXT FROM @getAccountID INTO @AccountID END -- Step 5 Close the cursor and clear the memory it used CLOSE @getAccountID DEALLOCATE @getAccountID http://www.kodyaz.com/articles/cursor.aspx http://msdn.microsoft.com/en-us/library/ms180169.aspx http://www.kodyaz.com/articles/t-sql-cursor-example-code.aspx http://msdn.microsoft.com/en- us/library/aa172595(SQL.80).aspx These are important for the homework http://www.eggheadcafe.com/software/aspnet/31208449/multipl e-rows-into-multiple-columns.aspx
  • 6. http://www.sqlteam.com/article/cursors-an-overview HOMEWORK 1) Modify todays example to print the employee number and name. I want you to print the employee number such that odd numbers are to the left and even numbers are to the right. 12311 John Doe 12312 Jane Smith 2) Using the Bowling League Database. Produce a list of the players on each team in team and player number order such that you skip a blank line in between the list for each team. Show the Team number and name and the player number and name. Hints for Homework Week 11 --Step 1 Create a table of Agregated Scores by Date_Bowled, Team_ID, Team_Name in a temporary file --Step 2 Use the schedule and the table you created in Step 1 (2 times) to align the team information onto one row for both teams in a temporary file (Hint: you should not be calculating anything here just joining two vertical records from step 1 into 1 horizontal record) --Step 3 Use the table you created in Step 2 to assign the points, remember to code for ties and put the results into a temporary file (Hint: your records are still horizontal here) --Step 4 Build points table for all weeks and teams into a temporary table that you will use for futher assignments (Hint:
  • 7. you want your records to be vertical here now that the points are calculated) Drop Table Schedule create table Schedule ( Date_Bowled Date ,Team1 VARCHAR(2) ,Team2 VARCHAR(2) ); GO INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','1','2'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','3','4'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','5','6'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','7','8'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','9','10'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','11','12'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','13','14');
  • 8. INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/10/15','15','17'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','1','3'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','2','4'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','5','7'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','6','8'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','9','12'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','10','11'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','13','17'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/17/15','14','15'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','1','4'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','2','3'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','5','8');
  • 9. INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','6','7'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','9','11'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','10','12'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','13','15'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/24/15','14','17'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','1','5'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','2','6'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','3','7'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','4','8'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','9','13'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','10','14'); INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','11','15');
  • 10. INSERT INTO Schedule (Date_Bowled, Team1, Team2) VALUES('01/31/15','12','17'); INSERT INTO ... Sheet1Date_BowledTeam1Team201/10/151201/10/153401/10/1 55601/10/157801/10/1591001/10/15111201/10/15131401/10/151 51701/17/151301/17/152401/17/155701/17/156801/17/1591201/ 17/15101101/17/15131701/17/15141501/24/151401/24/152301/2 4/155801/24/156701/24/1591101/24/15101201/24/15131501/24/ 15141701/31/151501/31/152601/31/153701/31/154801/31/15913 01/31/15101401/31/15111501/31/15121702/07/151602/07/15270 2/07/153802/07/154502/07/1591402/07/15101502/07/15111702/ 07/15121302/14/151702/14/152802/14/153502/14/154602/14/15 91502/14/15101702/14/15111302/14/15121402/21/151802/21/15 2502/21/153602/21/154702/21/1591702/21/15101302/21/151114 02/21/15121502/28/151902/28/1521002/28/1531102/28/1541202 /28/1551302/28/1561402/28/1571502/28/1581703/07/1511003/0 7/1521103/07/1531203/07/1541303/07/1551403/07/1561503/07/ 1571703/07/158903/14/1511103/14/1521203/14/1531303/14/154 1403/14/1551503/14/1561703/14/157903/14/1581003/21/151120 3/21/1521303/21/1531403/21/1541503/21/1551703/21/156903/2 1/1571003/21/1581103/28/1511303/28/1521403/28/1531503/28/ 1541703/28/155903/28/1561003/28/1571103/28/1581204/04/151 1404/04/1521504/04/1531704/04/154904/04/1551004/04/156110 4/04/1571204/04/1581304/11/1511504/11/1521704/11/153904/1 1/1541004/11/1551104/11/1561204/11/1571304/11/1581404/18/ 1511704/18/152904/18/1531004/18/1541104/18/1551204/18/156 1304/18/1571404/18/15815 CASE WHEN TEAM1_GAME1>TEAM2_GAME1 THEN 1 ELSE 0 END GAME1,
  • 11. if 12 % 2 =0 PRINT cast( 12 as char(4)) + ' '+'right' if 13 % 2 <>0 PRINT cast( 13 as char(4))+ ' '+'left' WHILE @@FETCH_STATUS=0 BEGIN IF @STUDENT<>@TEMP_STUDENT PRINT '' PRINT @STUDENT SELECT @[email protected] FETCH NEXT New Homework Delete scores for Week16 and Week17 Create a schedule table in your bowling database to store the attached list. Be careful that the fields you create have the same datatype and length and the equivalent fields in the scores table. Now the fun begins. Create a script that uses the schedule to
  • 12. read the scores table and produce a list that shows: HINT - You have to use the scores table twice in your query, once to link Team 1 for any given week and once to link Team 2 for any given week. Date, Team1 Number and Name, Total score for Game1, Game 2, Game 3 and Series and Team2 Number and Name, Total score for Game1, Game 2, Game 3 and Series . You also need to determine how many points each of the teams earned, they get 1 point for having the highest team score for Game 1, Game 2, Game 3, and Series. (So each match up should produce 4 points divided among the two teams.) Make the list in date and Team1 Number order. At the end list a summary of each team and how many points they earned using variables. There will be 480 points in total for the 15 weeks we bowled. Advanced SQL – Week 11 · The USE statement sets the current database · You must DECLARE variables before you use them, you can define one or more at the same time. DECLARE @variablename variabletype = value SET @TotalCost = 10 SET @TotalCost = @UnitCost * 1.1 DECLARE @Test money SET @Test = (SELECT MAX(Sal) FROM Emp) SELECT @Test
  • 13. PRINT 'The maximum salary is ' +CONVERT(varchar,@Test,1) go · There are a number of System Variables such as: @@ERROR, @@IDENTITY, @@ROWCOUNT · To separate a script into multiple batches, we use the GO statement. Using it causes all statements ince the beginning of the script or the last GO statement (whichever is closer) to be compiled into one execution plan and sent to the server independently of any other batches. · Variables declared in one batch are not available to other batches EXAMPLES SELECT convert(varchar,table_catalog,20) as "Database Name", table_name FROM information_schema.tables create table Billings ( BankerID INTEGER, BillingNumber INTEGER, BillingDate datetime, BillingTotal INTEGER, TermsID INTEGER, BillingDueDate datetime , PaymentTotal INTEGER, CreditTotal INTEGER); GO INSERT INTO Billings VALUES (5, 1, '2005-01-22', 110,
  • 14. 1,'2005-04-22',123,321); GO INSERT INTO Billings VALUES (2, 2, '2001-02-21', 165, 1,'2002-02-22',123,321.); GO INSERT INTO Billings VALUES (5, 3, '2003-05-02', 190, 1,'2005-04-12',123,321); GO INSERT INTO Billings VALUES (4, 4, '1999-03-12', 165, 1,'2005-04-18',123,321); GO INSERT INTO Billings VALUES (5, 5, '2000-04-23', 165, 1,'2005-04-17',123,321); GO INSERT INTO Billings VALUES (6, 6, '2001-06-14', 165, 1,'2005-04-18',123,321); GO INSERT INTO Billings VALUES (5, 7, '2002-07-15', 120, 1,'2005-04-19',123,321); GO INSERT INTO Billings VALUES (8, 8, '2003-08-16', 165, 1,'2005-04-20',123,321); GO INSERT INTO Billings VALUES (9, 9, '2004-09-17', 165, 1,'2005-04-21',123,321); GO INSERT INTO Billings VALUES (5, 0, '2005-10-18', 145,
  • 15. 1,'2005-04-22',123,321); GO DECLARE @MaxBilling money, @MinBilling money DECLARE @PercentDifference decimal(8,2) DECLARE @BillingCount int, @BankerIDVar int SET @BankerIDVar = 5 SET @MaxBilling = (SELECT MAX(BillingTotal) FROM Billings WHERE BankerID = @BankerIDVar) SELECT @MinBilling = MIN(BillingTotal), @BillingCount = COUNT(*) FROM Billings WHERE BankerID = @BankerIDVar SET @PercentDifference = (@MaxBilling - @MinBilling) / @MinBilling * 100 PRINT 'Maximum Billing is $' + CONVERT(varchar,@MaxBilling,1) + '.' PRINT 'Minimum Billing is $' + CONVERT(varchar,@MinBilling,1) + '.' PRINT 'Maximum is ' + CONVERT(varchar,@PercentDifference) + '% more than minimum.' PRINT 'Number of Billings: ' + CONVERT(varchar,@BillingCount) + '.' · Control of Flow Statements: IF … ELSE, CASE, WHILE
  • 16. IF <Boolean Expression> <SQL statement> | BEGIN <code series> END [ELSE <SQL statement> | BEGIN <code series> END] Variable = CASE <input expression> WHEN <when expression> THEN <result expression> […n] [ELSE <result expression>] END WHILE <Boolean expression> <sql statement> | [BEGIN <statement block> [BREAK] <sql statement> | <statement block> [CONTINUE] Transact-SQL Variableshttp://msdn.microsoft.com/en- us/library/ms187953.aspx T-SQL Loop Statement http://www.databasejournal.com/features/mssql/article.php/3100 621/T-SQL-Programming-Part-2---Building-a-T-SQL-Loop.htm Looping Statements http://publib.boulder.ibm.com/infocenter/db2luw/v9/index.jsp?t opic=/com.ibm.db2.udb.apdv.sql.doc/doc/c0024350.htm