May 14, 2010 at 12:51 am
CREATE PROCEDURE USP_UPDATESAL
@DPID INT
AS
BEGIN
DECLARE
@DPTID INT,
@SAL1 MONEY
SET @DPTID=(SELECT deptid FROM Humans WHERE deptid=@DPID)
SET @SAL1=
CASE @DPTID
WHEN 10 THEN 40000
WHEN 20 THEN 38000
WHEN 30 THEN 10000
WHEN 40 THEN 0
WHEN 50 THEN -1
END
UPDATE Humans SET SAL=@SAL1
WHERE deptid=@DPTID
END
May 14, 2010 at 1:00 am
dhaval_dsa (5/14/2010)
CREATE PROCEDURE USP_UPDATESAL@DPID INT
AS
BEGIN
DECLARE
@DPTID INT,
@SAL1 MONEY
SET @DPTID=(SELECT deptid FROM Humans WHERE deptid=@DPID)
SET @SAL1=
CASE @DPTID
WHEN 10 THEN 40000
WHEN 20 THEN 38000
WHEN 30 THEN 10000
WHEN 40 THEN 0
WHEN 50 THEN -1
END
UPDATE Humans SET SAL=@SAL1
WHERE deptid=@DPTID
END
then what to do
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
May 14, 2010 at 1:52 am
This query
SELECT deptid FROM Humans WHERE deptid=@DPID
Is returning more than one row, so you need to define which one. Use TOP 1 and an Order by clause.
Although Its superfluous anyway, as an equivalent is
SET @DPTID=@DPID
May 14, 2010 at 3:43 am
CREATE PROCEDURE USP_UPDATESAL
@DPID INT
AS
UPDATE Humans
SET SAL = CASE deptid
WHEN 10 THEN 40000
WHEN 20 THEN 38000
WHEN 30 THEN 10000
WHEN 40 THEN 0
WHEN 50 THEN -1
END
WHERE deptid = @DPID
The salaries are hard-coded, so why update them one department at a time?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply