Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can this SQL Statement Work?

Status
Not open for further replies.

chadau

Programmer
Nov 14, 2002
155
US
I have tried this but it doesn't seem to be working.

ALTER PROCEDURE GetApprover
@Cost money,
@EmployeeNumber varchar(5) = NULL

AS

DECLARE @ManagerCost money
DECLARE @MaxCost money

SET @ManagerCost = (SELECT Cost FROM Approver WHERE EmployeeNum = @EmployeeNumber)

SET @MaxCost = (SELECT TOP 1 Cost FROM Approver WHERE Cost > @ManagerCost ORDER BY Cost DESC)

RETURN @MaxCost
 
try
have tried this but it doesn't seem to be working.
Code:
ALTER PROCEDURE GetApprover
@Cost money,
@EmployeeNumber varchar(5) = NULL

AS

DECLARE @ManagerCost money
DECLARE @MaxCost money

(SELECT @ManagerCost = Cost FROM Approver WHERE EmployeeNum = @EmployeeNumber)

(SELECT TOP 1 @MaxCost = Cost FROM Approver WHERE Cost > @ManagerCost ORDER BY Cost DESC)
or maybe

Code:
ALTER PROCEDURE GetApprover
@Cost money,
@EmployeeNumber varchar(5) = NULL

AS

DECLARE @ManagerCost money
DECLARE @MaxCost money

(SELECT @ManagerCost = Cost FROM Approver WHERE EmployeeNum = @EmployeeNumber)
(SELECT @MaxCost = max(Cost) FROM Approver WHERE Cost > @ManagerCost)
 
Or
Code:
ALTER PROCEDURE GetApprover
@Cost money,
@EmployeeNumber varchar(5) = NULL

AS

DECLARE @ManagerCost money
DECLARE @MaxCost money
[green]-- Assuming all you really need is the @maxCost parameter[/green]
(SELECT max(Cost) as MaxCost FROM Approver WHERE Cost > (SELECT Cost FROM Approver WHERE EmployeeNum = @EmployeeNumber))

or
Code:
ALTER PROCEDURE GetApprover
@Cost money,
@EmployeeNumber varchar(5) = NULL

AS

DECLARE @MaxCost money
[green]-- Assuming all you really need is the @maxCost parameter[/green]
(SELECT @MaxCost = max(Cost)  FROM Approver WHERE Cost > (SELECT Cost FROM Approver WHERE EmployeeNum = @EmployeeNumber))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top