?
Solved

Problem with Case statement in Stored Procedure

Posted on 2009-07-14
3
Medium Priority
?
164 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
[X]
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
3 Comments
 
LVL 17

Accepted Solution

by:
pssandhu earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

752 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