Question: Mircoftsoft SQL Server 2008 T-SQL Please assist with the cord blow: Also having trouble with CONVERT(MONEY,dbo.EmpBonusAmt(E.Salary, D.Bonus),-1) . Please review code. Error Message: The 'EmpBonusAmt'

Mircoftsoft SQL Server 2008 T-SQL

Please assist with the cord blow: Also having trouble with CONVERT(MONEY,dbo.EmpBonusAmt(E.Salary, D.Bonus),-1) . Please review code.

Error Message:

The 'EmpBonusAmt' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.

AND

Error Message:

Msg 4121, Level 16, State 1, Procedure EmpBonusAmt, Line 24 [Batch Start Line 44] Cannot find either column "dbo" or the user-defined function or aggregate "dbo.EmpBonusAmt", or the name is ambiguous.

Code:

IF OBJECT_ID('dbo.EmpBonusAmt', 'P') IS NOT NULL DROP PROC dbo.EmpBonusAmt; GO

CREATE PROC dbo.EmpBonusAmt @Salary AS MONEY = NULL, @Bonus AS DECIMAL(2,2) = NULL AS SET NOCOUNT ON;

DECLARE @Comp MONEY; BEGIN IF @Salary BETWEEN 0 AND 50000 SET @Comp = @Salary ELSE IF @Salary BETWEEN 50001 AND 100000 SET @Comp = (@Salary * @Bonus) + @Salary ELSE IF @Salary > 100000 SET @Comp = 2*(@Salary * @Bonus) + @Salary

RETURN @Comp; END

BEGIN DECLARE @DeptId AS INT SET @DeptId = 392 IF @DeptId = 0

SELECT E.LName, E.FName, D.Name, CONVERT(MONEY,dbo.EmpBonusAmt(E.Salary, D.Bonus),-1) AS 'TotalComp' FROM Emp E LEFT JOIN EmpInDept ED ON E.Empid = ED.Empid LEFT JOIN Dept D ON ED.DeptId = D.DeptId

ELSE

SELECT E.LName, E.FName, D.Name, CONVERT(MONEY, dbo.EmpBonusAmt(E.Salary, D.Bonus),-1) AS 'TotalComp' FROM Emp E LEFT JOIN EmpInDept ED ON E.Empid = ED.Empid LEFT JOIN Dept D ON ED.DeptId = D.DeptId WHERE D.DeptId = @DeptId

END GO EXEC dbo.EmpBonusAmt GO

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!