Questions tagged [case]

In SQL, the CASE expression evaluates a list of conditions, returning the result for the first condition which evaluates to true. For programming languages' CASE questions, use the [switch-statement] tag instead.

Filter by
Sorted by
Tagged with
1688votes
31answers
4.1mviews

How do I perform an IF...THEN in an SQL SELECT?

How do I perform an IF...THEN in an SQL SELECT statement? For example: SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product
user avatar
622votes
2answers
1.8mviews

What is the Python equivalent for a case/switch statement? [duplicate]

Is there a Python equivalent for the case statement such as the examples available in VB.NET or C#?
user avatar
  • 6,389
593votes
11answers
3.1mviews

OR is not supported with CASE Statement in SQL Server

The OR operator in the WHEN clause of a CASE statement is not supported. How can I do this? CASE ebv.db_no WHEN 22978 OR 23218 OR 23219 THEN 'WECS 9500' ELSE 'WECS 9520' END as wecs_system
user avatar
  • 6,045
255votes
12answers
308kviews

How to use a switch case 'or' in PHP

Is there a way of using an 'OR' operator or equivalent in a PHP switch? For example, something like this: switch ($value) { case 1 || 2: echo 'the value is either 1 or 2'; break;...
user avatar
248votes
6answers
281kviews

PostgreSQL Crosstab Query

Does any one know how to create crosstab queries in PostgreSQL? For example I have the following table: Section Status Count A Active 1 A Inactive 2 B Active 4 ...
user avatar
214votes
5answers
278kviews

Can dplyr package be used for conditional mutating?

Can the mutate be used when the mutation is conditional (depending on the values of certain column values)? This example helps showing what I mean. structure(list(a = c(1, 3, 4, 6, 3, 2, 5, 1), b = ...
user avatar
175votes
10answers
596kviews

Can I use CASE statement in a JOIN condition?

The following image is a part of Microsoft SQL Server 2008 R2 System Views. From the image we can see that the relationship between sys.partitions and sys.allocation_units depends on the value of sys....
user avatar
171votes
4answers
332kviews

SQL Server: converting UniqueIdentifier to string in a case statement

We have a log table that has a message column that sometimes has an exception stack trace. I have some criteria that determines if the message has this. We do not want to show these messages to the ...
user avatar
  • 33.7k
171votes
10answers
281kviews

Using Case/Switch and GetType to determine the object [duplicate]

Possible Duplicate: C# - Is there a better alternative than this to ‘switch on type’? If you want to switch on a type of object, what is the best way to do this? Code snippet private int GetNodeType(...
user avatar
  • 15.3k
165votes
13answers
682kviews

SQL Switch/Case in 'where' clause

I tried searching around, but I couldn't find anything that would help me out. I'm trying to do this in SQL: declare @locationType varchar(50); declare @locationID int; SELECT column1, column2 FROM ...
user avatar
  • 5,396
155votes
5answers
51kviews

Ruby class types and case statements

What is the difference between case item.class when MyClass # do something here when Array # do something different here when String # do a third thing end and case item.class when MyClass....
user avatar
154votes
8answers
56kviews

How can I have lowercase routes in ASP.NET MVC?

How can I have lowercase, plus underscore if possible, routes in ASP.NET MVC? So that I would have /dinners/details/2 call DinnersController.Details(2) and, if possible, /dinners/more_details/2 call ...
152votes
1answer
313kviews

PostgreSQL CASE ... END with multiple conditions

Here is an extract of my table: gid | datepose | pvc ---------+----------------+------------ 1 | 1961 | 01 2 | 1949 | 3 | 1990 | 02 1 ...
user avatar
  • 3,251
150votes
3answers
861kviews

Case in Select Statement

I have an SQL statement that has a CASE from SELECT and I just can't get it right. Can you guys show me an example of CASE where the cases are the conditions and the results are from the cases. For ...
user avatar

15 30 50 per page
1
2 3 4 5
576