Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem with Case statement in Stored Procedure

Posted on 2009-07-14
3
159 Views
Last Modified: 2012-05-07
What am I doing wrong here?
Case when @Password <> '' then
	Update vUser_Info
	Set
		[USERID] = @USERID,
		[Password] = @Password,
		[FIRST_NAME] = @FIRST_NAME,
		[LAST_NAME] = @LAST_NAME,
		[EMAIL] = @EMAIL,
		[ROLEID] = @ROLEID,
		[STATUS] = @STATUS,
		[CORPORATE] = @CORPORATE
	Where [UserID] = @UserID	
	End
	
	Case when @Password = '' then
	Update vUser_Info
	Set
		[USERID] = @USERID,
		[FIRST_NAME] = @FIRST_NAME,
		[LAST_NAME] = @LAST_NAME,
		[EMAIL] = @EMAIL,
		[ROLEID] = @ROLEID,
		[STATUS] = @STATUS,
		[CORPORATE] = @CORPORATE
	Where [UserID] = @UserID	
	End

Open in new window

0
Comment
Question by:mattkovo
3 Comments
 
LVL 17

Accepted Solution

by:
pssandhu earned 500 total points
ID: 24852229
You need to use the IF statement:
IF @Password <> ''
BEGIN
	Update vUser_Info
	Set
		[USERID] = @USERID,
		[Password] = @Password,
		[FIRST_NAME] = @FIRST_NAME,
		[LAST_NAME] = @LAST_NAME,
		[EMAIL] = @EMAIL,
		[ROLEID] = @ROLEID,
		[STATUS] = @STATUS,
		[CORPORATE] = @CORPORATE
	Where [UserID] = @UserID	
END
ELSE
BEGIN
         Update vUser_Info
	Set
		[USERID] = @USERID,
		[FIRST_NAME] = @FIRST_NAME,
		[LAST_NAME] = @LAST_NAME,
		[EMAIL] = @EMAIL,
		[ROLEID] = @ROLEID,
		[STATUS] = @STATUS,
		[CORPORATE] = @CORPORATE
	Where [UserID] = @UserID	
END

Open in new window

0
 

Author Closing Comment

by:mattkovo
ID: 31603386
That's exactly what I came up with.  THanks!  I couldn't delete the post fast enough!
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24852257
It should be an IF ELSE construct instead of CASE statement.

Hope you meant @Password IS NULL and @Password IS NOT NULL
instead of @Password = '' and  @Password <> ''

If that is the case, then replace it and that will work.
Hope this helps
If @Password <> ''
begin
Update vUser_Info
Set
        [USERID] = @USERID,
        [Password] = @Password,
        [FIRST_NAME] = @FIRST_NAME,
        [LAST_NAME] = @LAST_NAME,
        [EMAIL] = @EMAIL,
        [ROLEID] = @ROLEID,
        [STATUS] = @STATUS,
        [CORPORATE] = @CORPORATE
Where [UserID] = @UserID        
End
ELSE IF @Password = ''
begin
Update vUser_Info
Set
        [USERID] = @USERID,
        [FIRST_NAME] = @FIRST_NAME,
        [LAST_NAME] = @LAST_NAME,
        [EMAIL] = @EMAIL,
        [ROLEID] = @ROLEID,
        [STATUS] = @STATUS,
        [CORPORATE] = @CORPORATE
Where [UserID] = @UserID        
End

Open in new window

0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question