Works fine for me unless I forget to include the code from
DECLARE @employeeInfo EmployeeInfo;
If I omit that DECLARE from my selection before hitting F5 then I get the same error as you.
I.e. you have to run all of the following:
DECLARE @employeeInfo EmployeeInfo;
DECLARE @TotalHours INT;
INSERT @employeeInfo
SELECT e.employeeID, @TotalHours
FROM HumanResources e
WHERE e.employeeID = 2 AND @TotalHours = 30
DECLARE @allowanceInfo AllowanceInfo;
DECLARE @employeeAllowanceInfo EmployeeInfo;
INSERT @allowanceInfo
SELECT e.employeeID, pa.allowanceID, pa.Amount
FROM HumanResources e, Allowance a, PayAllowance pa, EmployeeAllowance ea, @employeeAllowanceInfo emp
WHERE e.employeeID = emp.employeeID AND pa.AllowanceID = a.AllowanceID AND a.AllowanceID = ea.AllowanceID AND pa.allowanceID = 1
EXECUTE usp_createPayroll
@startDatePeriod = '01-01-2015 23:59:59'
,@endDatePeriod = '01-31-2015 23:59:59'
,@taxID = 2
,@numberofTotalHours = @employeeInfo
,@Allowance = @allowanceInfo
GO
I can't really see the point of creating a Stored Procedure just to drop it immediately after running it.
And I don't think
IF EXISTS(SELECT * FROM sys.Databases WHERE name='usp_createPayroll')
BEGIN
DROP PROCEDURE dbo.usp_createPayroll
DROP TYPE dbo.EmployeeInfo
DROP TYPE dbo.AllowanceInfo
END
is doing what you think it is - it should probably be
IF EXISTS(SELECT * FROM sys.procedures WHERE name='usp_createPayroll')
...