Questions tagged [case-expression]

SQL equivalent for IIf or Switch/case constructs

34 questions
4
votes
4 answers

SQL Case statement

SELECT MIN(Measurement), (CASE 'NonDesMin' WHEN len(measurement) = 6 then '0000' ELSE '000' END) as [Min] FROM LeachingView WHERE DateTimeStamp > '2011-01-01' AND measurement > 0 This is my SQL…
zach
  • 1,281
  • 7
  • 27
  • 41
4
votes
0 answers

How to write this case statement in query dsl

I have a fairly straight forward case statement to write in querydsl: case when column >= 1 and column < 31 then 1 else 0 end I tried the following…
AVM
  • 303
  • 1
  • 4
  • 15
3
votes
6 answers

Why should I use case expressions if I can use "equations"?

I'm learning Haskell, from the book "Real World Haskell". In pages 66 and 67, they show the case expressions with this example: fromMaybe defval wrapped = case wrapped of Nothing -> defval Just value -> value I remember a…
JMCF125
  • 378
  • 3
  • 18
2
votes
2 answers

Lead and case expression

I have this table: ID Date ----------------- 1 1/1/2019 1 1/15/2019 Expected output: ID DATE LEAD_DATE ------------------------- 1 1/1/2019 1/14/2019 1 1/15/2019 SYSDATE SQL: SELECT *, CASE WHEN LEAD…
Mr John
  • 231
  • 1
  • 3
  • 18
2
votes
2 answers

MySQL - Stored Procedure - Using a Case Expression inside Case Statement?

I'm currently in the process of writing a stored procedure that uses case statements to determine what queries to run. Inside one of my queries is a case expression and I get a syntax error every time I try to save the altered procedure. The…
2
votes
2 answers

sql case in where clause

I've a report in SSRS and one of the parameters is based on whether a person attended an interview, failed to attend or no current feedback. The SQL is as follows: SELECT (C.Forename + ' ' + C.Surname) as Fullname, C.NINO, …
1
vote
3 answers

conditions in Case statement

select min(measurement), part_desc (case len(measurement) when 6 then '0000' + part_desc else '000' + part_desc end) from LeachingView where DateTimeStamp > '2011-01-01' and measurement > 0 group by measurement,…
zach
  • 1,281
  • 7
  • 27
  • 41
1
vote
1 answer

Case expressions and "overloading" parameter count

I am new to ML, and wanted to use case expressions and pattern matching in the following way. fun myFun(a,b) = myFun(a,b,[]) | myFun(a,b,c) = (*do something here*) | myFun(a,b,d) = (*do something here as well*); so is it possible to have…
Huzo
  • 1,652
  • 1
  • 21
  • 52
1
vote
2 answers

order by with a case expression

I have a complex order by with case expression. ORDER BY CASE WHEN field_1 = ? then 0 WHEN field_2 = ? then 1 ELSE 3 end ASC i want to order the inner results by a field_3 for example my table is - index | field_1 | field_2 |…
ilan
  • 4,402
  • 6
  • 40
  • 76
1
vote
1 answer

Ruby case expression unexpected keyword

I am new to Ruby. My past is in Java. I am trying to use a switch case, apparently known as a case expression in Ruby. I want to accept user input, check that input to see if it includes certain characters, and then substitute those characters with…
Blank Reaver
  • 225
  • 3
  • 5
  • 17
1
vote
2 answers

Invalid # of Arguments in a stuff statement with case in SQL

I have to do an insert into a single column/row from a source of multiple values. I'm using the stuff case and I'm so close, but I'm missing one of the expected returns, so I'm not sure what I need to do to make sure I get the results I'm looking…
SQL_Noob
  • 1,161
  • 1
  • 9
  • 18
1
vote
5 answers

Use of CASE statement values in THEN expression

I am attempting to use a case statement but keep getting errors. Here's the statement: select TABLE1.acct, CASE WHEN TABLE1.acct_id in (select acct_id from TABLE2 …
YeeHaw
  • 13
  • 4
1
vote
3 answers

What does CASE SUM(total_of_A) WHEN 0 THEN 0 ELSE SUM(B) / SUM(total_of_A) END mean

Trying to understand the CASE (Transact-SQL) expression, but ended up with lot of confusion. Can anyone please explain the following statement in simple words? CASE SUM(total_of_A) WHEN 0 THEN 0 ELSE SUM(B) / SUM(total_of_A) END; I read the…
PineCone
  • 2,193
  • 12
  • 37
  • 78
1
vote
3 answers

Case statement in stored procedure - Unknown System Variable

I'm trying to use a case statement to update a column based on the value of another column. My table called 'rma' in MySQL is as follows: ID | rma_number | serial_number | ref_status_id 1 | 9898 | 123456 …
brandozz
  • 1,059
  • 6
  • 20
  • 38
0
votes
1 answer

case of redundant pattern matching

I am trying to write a haskell interpeter for different kind of statements. One such is a switch statement. I have done the following as of now but I am stuck and I keep getting redundant pattern matching warning for the ( _ -> if length ) line in…
noogler
  • 167
  • 1
  • 2
  • 16
1
2 3