Questions tagged [case-statement]

A case statement allows sequences of SQL statements to be selected for execution based on search or comparison criteria, and is typically used in stored procedures. Do not use this tag, use [switch-statement] instead.

The CASE statement provides a mechanism for conditional execution of SQL statements.

It exists in two forms: the simple case and the searched case.

The simple case involves an equality comparison between one expression and a number of alternative expressions, each following a WHEN clause.

The searched case involves the evaluation for truth of a number of alternative search conditions, each following a WHEN clause.

In each form of the CASE it is the first WHEN clause to evaluate to true, working from the top down, that determines which sequence of SQL statements will be executed.

There may be one or more SQL statements following the THEN clause for each WHEN. If none of the WHEN clauses evaluates to true, the SQL statements following the ELSE clause are executed. If none of the WHEN clauses evaluates to true and there is no ELSE clause, an exception condition is raised to indicate that a case was not found.

Providing an ELSE clause supporting an empty compound statement will avoid an exception condition being raised, in cases where no ‘else’ action is required, when none of the WHEN alternatives evaluates to true.

430 questions
11
votes
5 answers

case-statement or if-statement efficiency perspective

Possible Duplicates: Is "else if" faster than "switch() case"? What is the relative performance difference of if/else versus switch statement in Java? I know that case statements can be implemented with jump tables. Does this make them more…
sixtyfootersdude
  • 25,859
  • 43
  • 145
  • 213
11
votes
5 answers

Is There Anything Like a Templatized Case-Statement

So I have this really ugly code: template std::conditional_t
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
10
votes
3 answers

Haskell: Multiple Case Statements in Single Function

I want to include more than one case statement in a Haskell function (see below for an example of a hypothetical function). However, it is not legal Haskell. What is a better way of accomplishing the same thing? Furthermore, if the case statements…
well actually
  • 11,810
  • 19
  • 52
  • 70
8
votes
3 answers

How can I test that a value is within a range with a "case" statement instead of an "if" statement?

Can the following if statement be converted to a case statement? if (Number >= 5) and (Number <= 10) then lblAnswer.Caption := 'in range' else lblAnswer.Caption := 'out of range'; My Answer : Yes it can case (number >= 5) and (Number <= 10)…
user1000441
  • 85
  • 1
  • 1
  • 3
8
votes
2 answers

Verilog Barrel Shifter

I want to create a 64-bit barrel shifter in verilog (rotate right for now). I want to know if there is a way to do it without writing a 65 part case statement? Is there a way to write some simple code such as: Y = {S[i - 1:0], S[63:i]}; I tried…
Robert Cardona
  • 1,068
  • 5
  • 18
  • 31
7
votes
2 answers

Why am I getting this warning from GHCi?

I'm getting a curious warning when pattern matching, but only when OverloadedStrings is enabled... $ ghci -Wall GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp…
dave4420
  • 46,404
  • 6
  • 118
  • 152
7
votes
3 answers

Delphi typed constants in case statements

What is the most elegant (or least ugly) way of using typed constants in a case statement in Delphi? That is, assume for this question that you need to declare a typed constant as in const MY_CONST: cardinal = $12345678; ... Then the Delphi…
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
7
votes
8 answers

What is the Fastest Way to Check for a Keyword in a List of Keywords in Delphi?

I have a small list of keywords. What I'd really like to do is akin to: case MyKeyword of 'CHIL': (code for CHIL); 'HUSB': (code for HUSB); 'WIFE': (code for WIFE); 'SEX': (code for SEX); else (code for everything…
lkessler
  • 19,819
  • 36
  • 132
  • 203
7
votes
3 answers

SQL compare string

CASE WHEN ' 1a' = ' 1a ' THEN 'EQUAL - but it isn´t- HELP!!!!' ELSE 'UNEQUAL' END from dual; Can anybody help me, an explain to me why the DB say that these 2 strings are the same ' 1a' = ' 1a …
Max Müller
  • 71
  • 1
  • 2
6
votes
2 answers

Identical case condition

I am converting some VB.NET code to C#, as I am more comfortable with it and it helps me in resolving issues faster. However, I came across this code which is NOT an error in VB.NET — but converting it to C# is generating a compiler error. VB.NET…
Sekhar
  • 5,614
  • 9
  • 38
  • 44
6
votes
2 answers

Exporting variable from case Warning

When developing with erlang, I sometimes use case statements like this case Status of 1 -> Variable = "Something"; 2 -> Variable = "Something else"; 3 -> Variable = {"Something very different", [1,2,3]} end to…
Sergey Ovchinnik
  • 472
  • 4
  • 16
6
votes
3 answers

How to handle multiple values inside one case?

How to handle multiple values inside one case? So if I want to execute the same action for value "first option" and "second option"? Is this the right way? switch(text) { case "first option": { } case "second option": { …
CodeBreaker
  • 73
  • 1
  • 1
  • 7
5
votes
3 answers

Writing case statements

#!/bin/bash until [read command -eq "end"] do echo What command would like to run? read command if [$command -eq "my-tweets"]; then node liri.js $command fi if [$command -eq "do-what-it-says"];then node liri.js $command fi if [$command -eq…
5
votes
4 answers

How to assign multiple values in CASE statement?

I need to assign two values to my select based on a CASE statement. In pseudo: select userid , case when name in ('A', 'B') then 'Apple' when name in ('C', 'D') then 'Pear' end as snack from table ; I am assigning a…
Pr0no
  • 3,910
  • 21
  • 74
  • 121
5
votes
2 answers

Is it possible to create a variable and make its assignment based on certain conditions in a cypher query?

I am trying to create an array of values that will be assigned based on the outcome of a case test. This test will be inside a query that I already know works with a preset value in the query. The query I am trying to embed in the case test is…
cluemein
  • 884
  • 13
  • 27
1
2
3
28 29