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

Java socket, create own universal method // vicious circle

Can you please help me with the answer, please? I've read a lot, but can understand, how to organize the code. I want to create my own method to work with the Network and call it time to time in a program. But this compilation error makes me…
-1
votes
1 answer

SQL Case statement with subquery

can somebody tell me what wrong with my case statement? select (case when (select top 1 descr from t1 inner join t2 on t2.id = t1.id where t1.code = '17418')= 'C' Then 'Cancelled'
when (select top 1 descr from t1 inner join t2 on…
Jason312
  • 197
  • 1
  • 1
  • 10
-1
votes
1 answer

Count the number of cases in switch statement(Case) in Delphi

I am new to Delphi and I want to count the number of cases from the case statement in delphi. For example in this code there are 3 case statement and one default case statement, so the total case in this is 4. How do I make a count of this? colour…
Papagaio
  • 13
  • 3
-1
votes
1 answer

Subtracting specific date from a date field in a Netsuite Case Statement

We are trying to pull data for year end analysis and have a case statement working inside of results of a netsuite search that normally utilizes a calculation using {today} within the formula. However, since we want to view the results as if "today"…
T.F.
  • 1
  • 1
-1
votes
2 answers

sql select statement inside case

let say i wanna create something like this select t.*, (case when (select name from table2 where idtable2 = t.idtable1)= NULL then '0' end) as result from table1 t how can i do it? thank you sorry my mistakes,yes that statement it…
Vincent
  • 31
  • 1
  • 4
-1
votes
1 answer

sum with multiple condition in sql server

I have a query that captures the sum with multiple condition (see below), however, i would like to do the same thing but within a case statement if possible. Original Query: select sum(Total Cost) from Table where date between '7/20/2016' and…
ZYK
  • 9
  • 1
  • 1
  • 2
-1
votes
2 answers

SQL Server : CASE statement varbinary comparison has unexpected behavior

UPDATE: It appears there may be some certificate or rule running on open queries with enrypted column data. I have discovered that the following produces an unencrypted value concat 'more'. I will have to verify with our DBA what may cause this…
-1
votes
2 answers

SQL Server : create view inside CASE

I am trying to create views inside a case statement, but SQL Server does not allow it. Here an example: SELECT value, CASE value WHEN 'value1' THEN (Create View as (Select ... From ... Where...)) WHEN 'value1' THEN (Create View as (Select ...…
bpesunny
  • 81
  • 1
  • 1
  • 6
-1
votes
1 answer

Multiple case statements in SQLLDR Control file

I am using a control file to load data into Oracle 11g which is running on windows 7 machine. I have trouble loading the data with the following case statement and I tried different ways, couldn't succeed. Any suggestion? (In the log file the error…
bigZbuzzzinga
  • 17
  • 1
  • 5
-1
votes
2 answers

Case Statement Validation

I need to validate a certain textbox input to only accept numerical data between the range of 0-10 and so that is shows an error message in a label when the button is pushed and the data isn't within those specifications. This then clears the…
-1
votes
2 answers

Multiple SQL IF statement

So if I got a column like this: Notes A, B, C A A, C A, F How do i do a multiple if statements that would look through the column and if it has an A print "cash", if it has a B print "Check", if it has a C print "money order". And…
jjohnson
  • 203
  • 1
  • 5
  • 16
-1
votes
2 answers

Break for case statement

How can I prevent to run *) (with echo "Other") in follow code? I want when $a is equal 18 just echo "A". Now echo "A" and "Other" case "$a" in [17-20]) echo "A" ;; *) echo "Other" ;; esac
Daniyal
  • 119
  • 3
  • 8
-1
votes
1 answer

SQL Server 2005. I need help building AR aging report . What is wrong with the script?

SELECT invno,invdte, CASE WHEN (invdte >= (getdate() - 30) and itotal !=0 THEN 'itotal') AS '0-30' WHEN (invdte BETWEEN getdate(), - 31) AND (getdate(), - 60) AND itotal !=0 THEN 'itotal') AS '31-60' WHEN (invdte…
-1
votes
2 answers

iSeries DB2 SQL - Update Variable in UDF Using CASE Statement

I am attempting to create a user defined function for DB2 and cannot figure it out. I am much more comfortable with t-sql, which would do this in about a dozen ways. I need help as all I get in return are cryptic error messages that tell me there…
-2
votes
1 answer

MS-SQL getting case specific values

We have a table LogicalTableSharing as follows: For a specific requirement, we need to take PhysicalCompany of each TableCode into a variable. We tried a case-based query as follows: declare @tablecode varchar(50) declare @inputcompany…
sweenal
  • 67
  • 8
1 2 3
28
29