Solved

Problem with Case statement in Stored Procedure

Posted on 2009-07-14
3
157 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now