Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CASE statement and stored procedure

Author  Topic 

vaux17
Starting Member

1 Post

Posted - 2011-05-26 : 06:00:20
In my example I am trying replace some values by an other one .The SP below is fully validated but the problem is that I find no way to
allocate Emp_Name to @Emp_Name without getting an error message.

My goal is to use the SP to replace AAA by BBB .The value AAA belongs to the attribute Emp_Name .

How would you proceed to allocate Emp_Name to @Emp_Name

Emp_Number Emp_Name Emp_Hiredate
1 AAA 260166
2 BBB 260167


create PROCEDURE GET_EMP_REC8
@Emp_Number int,
@Emp_Name varchar(20) OUTPUT,
@Emp_Hiredate datetime OUTPUT
as
SELECT @Emp_Hiredate= Emp_Hiredate ,
(CASE @Emp_Name
WHEN 'AAA' THEN 'BBB'
ELSE 'UNKNOWN'
END)
FROM Employee
WHERE empno = @Emp_Number
RETURN 0


Fab

jfarrugia
Yak Posting Veteran

55 Posts

Posted - 2011-05-26 : 06:16:26
have you tried?

-- first two lines just for testing
declare @Emp_Name as varchar(50)
set @Emp_Name = 'AAA'

select
CASE WHEN @Emp_Name = 'AAA'
THEN 'BBB'
END


Where software development knowledge meets the reader
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2011-05-26 : 06:17:00
SELECT @Emp_Hiredate= Emp_Hiredate ,
@Emp_Name
= (CASE WHEN Emp_Name = 'AAA' THEN 'BBB'
ELSE 'UNKNOWN'
END)
FROM Employee
WHERE Emp_Number = @Emp_Number
RETURN 0
Go to Top of Page
   

- Advertisement -