Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem with Case statement in Stored Procedure

Posted on 2009-07-14
3
Medium Priority
?
165 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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