-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e675a9
commit d954432
Showing
1 changed file
with
59 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,59 @@ | ||
/* | ||
Today's Topic: Stored Procedures | ||
*/ | ||
|
||
|
||
CREATE PROCEDURE Temp_Employee | ||
AS | ||
DROP TABLE IF EXISTS #temp_employee | ||
Create table #temp_employee ( | ||
JobTitle varchar(100), | ||
EmployeesPerJob int , | ||
AvgAge int, | ||
AvgSalary int | ||
) | ||
|
||
|
||
Insert into #temp_employee | ||
SELECT JobTitle, Count(JobTitle), Avg(Age), AVG(salary) | ||
FROM SQLTutorial..EmployeeDemographics emp | ||
JOIN SQLTutorial..EmployeeSalary sal | ||
ON emp.EmployeeID = sal.EmployeeID | ||
group by JobTitle | ||
|
||
Select * | ||
From #temp_employee | ||
GO; | ||
|
||
|
||
|
||
|
||
CREATE PROCEDURE Temp_Employee2 | ||
@JobTitle nvarchar(100) | ||
AS | ||
DROP TABLE IF EXISTS #temp_employee3 | ||
Create table #temp_employee3 ( | ||
JobTitle varchar(100), | ||
EmployeesPerJob int , | ||
AvgAge int, | ||
AvgSalary int | ||
) | ||
|
||
|
||
Insert into #temp_employee3 | ||
SELECT JobTitle, Count(JobTitle), Avg(Age), AVG(salary) | ||
FROM SQLTutorial..EmployeeDemographics emp | ||
JOIN SQLTutorial..EmployeeSalary sal | ||
ON emp.EmployeeID = sal.EmployeeID | ||
where JobTitle = @JobTitle --- make sure to change this in this script from original above | ||
group by JobTitle | ||
|
||
Select * | ||
From #temp_employee3 | ||
GO; | ||
|
||
|
||
exec Temp_Employee2 @jobtitle = 'Salesman' | ||
exec Temp_Employee2 @jobtitle = 'Accountant' |