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
-2
votes
1 answer

CASE statement between two tables (Advanced)

I wasn't sure how else to do this, I'm assuming a CASE statement but let me know if there's a better way. I have two tables that keep track of race horses. Once keeps track of their information, the other their race results. Some of these horses are…
-2
votes
1 answer

Need To Transform Sybase Table Query Results Into More Granular Interpretation

I'd like to write an SQL statement in code which works like a case statement of some sorts in order to identify that a certain "indicator" represents two different "meanings". When Indicator in the table below = "Underlying" I want an additional row…
-2
votes
3 answers

T-SQL Case statement with 2 column values SQL Server

I am trying to use a Case statement to check if one column has a certain value and based on that value set another column equal to a certain value. Any help on how to do this would be greatly appreciated. Something Like This: SELECT …
-2
votes
3 answers

Looping VBA Case Statement

Currently I have the same code in each Case statement and sometimes I have to repeat it 50 times, is there a way to simplify this: For each one I am having to create 40 frames each one names VarFrame1...VarFrame40 as well I am creating this code in…
user1660680
  • 97
  • 2
  • 11
-3
votes
4 answers

SQL Case statement query

See image. I have a table full of records relating to specific departments. If the department name is held under the field 'StandardWork' but after the word 'Support -' what is the SQL command to create a new column called Service which will…
JsonStatham
  • 9,770
  • 27
  • 100
  • 181
-3
votes
1 answer

H all,, I need to create a formula(text) in Netsuite is anyone is able to give me a hint how to finish it please? UPDATED

I need to do this in formula(text) if custitem_prod_grade_field equals A then Pack/Batch Size equals custitem_unitsperpallet ELSE custitem10 * reordermultiple, if any field is null then default to reordermultiple. This will allow us to order in full…
beetle_juice
  • 51
  • 2
  • 11
-3
votes
3 answers

Comparison sign 'greater than' and 'equal to' in CASE SQL Statement

I am new to SQL Server and this is my first post. I am getting the message "incorrect syntax near '=' when using the Case Statement. Here is an example of my code: Select * , CASE when a > b THEN b = a when c > d THEN d = c when e >…
MsAB2
  • 1
  • 1
  • 3
-3
votes
1 answer

can i use case inside if statement in pascal

I want to using case on if statement, can I use it? Because I always got error when i compile it ;w; Error I got: Tahun.pas(26,21) Fatal: Syntax error, ";" expected but "ELSE" found Tahun.pas(0) Fatal: Compilation aborted Here my code: uses…
Clesuka
  • 3
  • 3
-3
votes
4 answers

How do I use one function to call the other function by if/case statement?

Does anyone know what typo I made, because my editor, and I can't seem to make it work number=5; switch (number) { case 5: box.onclick = function1; break; case 50: box.onclick = function2; break; } I've also…
-5
votes
4 answers

Why we are using ' : ' instead of ' ; ' in case control instruction?

I need to know why we are using colon on keyword case in c programming and not semicolon? /*valid statement*/ case 1: do this; case 2: do this; /*why is invalid to write */ case 1; do this; case 2; do this; help me please
Husmukh
  • 66
  • 5
1 2 3
28
29