I want to use CASE statement to update some records in sql server 2005

0 votes
UPDATE dbo.TestStudents  
SET LASTNAME = 
( CASE  
WHEN (LASTNAME = 'AAA') THEN 'BBB' 
WHEN (LASTNAME = 'CCC') THEN 'DDD' 
WHEN (LASTNAME = 'EEE') THEN 'FFF' 
ELSE  (LASTNAME)
END )

The statement serves its function, but the else condition scans every table row. Can I leave the unaffected rows alone in any way?

Sep 2 in Database by Kithuzzz
• 12,240 points
35 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Database

0 votes
0 answers

How to update two tables in one statement in SQL Server 2005?

In one operation, I want to update ...READ MORE

Aug 20 in Database by Kithuzzz
• 12,240 points
28 views
0 votes
0 answers

How would I use excel to generate a large update sql statement?

I know there's a way to have ...READ MORE

Mar 30 in Database by Edureka
• 13,640 points
116 views
0 votes
1 answer

How to upsert (update or insert) in SQL Server 2005

Try to check for existence: IF NOT EXISTS ...READ MORE

answered Sep 18 in Database by narikkadan
• 20,880 points
22 views
0 votes
1 answer

Best way to do nested case statement logic in SQL Server

Try some sort of COALESCE trick: SELECT COALESCE( ...READ MORE

answered Sep 19 in Database by narikkadan
• 20,880 points
11 views
0 votes
1 answer

SQL Server CASE .. WHEN .. IN statement

Two forms of CASE statements are getting ...READ MORE

answered Feb 8 in Database by Vaani
• 7,020 points
78 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

There's problem in all of them and ...READ MORE

answered Feb 9 in Database by Neha
• 8,920 points
167 views
0 votes
1 answer

How can we UPDATE from a SELECT in an SQL Server

We can firstly use SELECT statement to fetch ...READ MORE

answered May 27 in Others by Avinash
• 240 points
65 views
0 votes
0 answers

SQL update query using joins

A value that is returned from a ...READ MORE

Sep 6 in Database by Kithuzzz
• 12,240 points
20 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3 in Database by Vaani
• 7,020 points
121 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4 in Database by Vaani
• 7,020 points
45 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP