Solved

Problem with Case statement in Stored Procedure

Posted on 2009-07-14
3
161 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 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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