Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Statement

Status
Not open for further replies.

beth4530

Technical User
May 5, 2011
44
US
Is it possible to have a case statement as such;

Case When Field_1 = x then Field_2 = n END

 
no.

Something similar to this though...

Set Field_2 = Case When Field_1 = x Then n Else NULL End

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Sorry, I'm a newbie when it comes to sql.

I'm getting an error "incorrect syntax near "set
 
If this example is being used in a SELECT, you could try...

Code:
SELECT Field_1, CASE WHEN Field_1 = x THEN n ELSE Field_2 END Field_2
  FROM YourTable
 
It depends on what you are trying to do:

If you are just trying to retrieve data a certain way, use DaveInIowa's suggestion.
If you are trying to update data in a table, use gmmastros' suggestion as part of an update statement.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top