• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

sql case statement

sql case statement
multiple ifs  1 then

i dont want to do
if...
if..
if...
because there is only two thens total


0
rgb192
Asked:
rgb192
2 Solutions
 
Ephraim WangoyaCommented:
It takes the form


case
  when condition1 then
    Your statement
  when condition2 then
    Your statement
  when condition3 then
    Your statement
  else
    Your statement
end
0
 
raulggonzalezCommented:
Or

case Input_expresion
     WHEN value THEN something
    WHEN value2 THEN something2
    ELSE something else
END As Colname

http://msdn.microsoft.com/en-us/library/ms181765.aspx

but you only can use it inside a query, if you want to use it like in other programming languages, I'm afraid you need to use

if
else if
else if
else



cheers
0
 
rgb192Author Commented:
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now