There are two formats of case expression. You can do CASE
with many WHEN
as;
CASE WHEN Col1 = 1 OR Col3 = 1 THEN 1 WHEN Col1 = 2 THEN 2 ... ELSE 0 END as Qty
Or a Simple CASE
expression
CASE Col1 WHEN 1 THEN 11 WHEN 2 THEN 21 ELSE 13 END
Or CASE
within CASE
as;
CASE WHEN Col1 < 2 THEN CASE Col2 WHEN 'X' THEN 10 ELSE 11 END WHEN Col1 = 2 THEN 2 ... ELSE 0 END as Qty
Related Posts:
- Rename column SQL Server 2008
- Efficiently convert rows to columns in sql server
- T-SQL split string based on delimiter
- How do I do multiple CASE WHEN conditions using SQL Server 2008?
- SQL Server WITH statement
- SQL Server Insert if not exists
- SQL Server: Invalid Column Name
- Arithmetic overflow error converting numeric to data type numeric
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- Sql query to insert datetime in SQL Server
- Microsoft OLE DB Provider for SQL Server error ‘80004005’
- Bulk load data conversion error (truncation)
- Can I use multiple “with”?
- Backup a single table with its data from a database in sql server 2008
- How can I group by date time column without taking time into consideration
- Arithmetic overflow error converting varchar to data type numeric. ’10’ <= 9.00
- Filter data based on date in sql
- Varchar invalid for Sum operator
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- SQL WITH clause example [duplicate]
- The wait operation timed out. ASP
- Conversion failed when converting date and/or time from character string while inserting datetime
- how to fix oracle ORA-01722 invalid number error
- SQL query to select dates between two dates
- MySQL – Operand should contain 1 column(s)
- SQL SELECT WHERE field contains words
- Must declare the scalar variable
- How can I do a FULL OUTER JOIN in MySQL?
- MySQL query String contains
- How do I escape a single quote in SQL Server?
- Finding duplicate values in a SQL table
- MySQL Cannot Add Foreign Key Constraint
- Enable ‘xp_cmdshell’ SQL Server
- How do I import an SQL file using the command line in MySQL?
- mysql Foreign key constraint is incorrectly formed error
- Can a foreign key be NULL and/or duplicate?
- How do composite indexes work?
- Difference between JOIN and INNER JOIN
- MySQL “WITH” clause
- Error Code: 2013. Lost connection to MySQL server during query
- SQL join on multiple columns in same tables
- What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?
- Sql query – getting rid of hard-coded values
- ORA-00918: column ambiguously defined in SELECT *
- Combining “LIKE” and “IN” for SQL Server
- How To Run A Github Repository?
- SQL Switch/Case in ‘where’ clause
- Oracle – ORA-01489: result of string concatenation is too long [duplicate]
- How can I get column names from a table in SQL Server?
- “ORA-01438: value larger than specified precision allowed for this column” when inserting 3
- Algebra Relational sql GROUP BY SORT BY ORDER BY
- Oracle “Partition By” Keyword
- ERROR: there is no unique constraint matching given keys for referenced table “bar”
- What is the equivalent of ‘describe table’ in SQL Server?
- How do I query for all dates greater than a certain date in SQL Server?
- Add a column with a default value to an existing table in SQL Server
- SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO [duplicate]
- Using group by on multiple columns
- What is the purpose of using WHERE 1=1 in SQL statements?
- Conversion failed when converting the varchar value ‘simple, ‘ to data type int
- postgresql: error duplicate key value violates unique constraint
- Is there a workaround for ORA-01795: maximum number of expressions in a list is 1000 error?
- How do you force mysql LIKE to be case sensitive?
- ORA-06502: PL/SQL: numeric or value error: character string buffer too small
- What is the difference between a stored procedure and a view?
- How to order by with union in SQL?
- Update statement with inner join on Oracle
- PostgreSQL create table if not exists
- Incorrect syntax near ”
- MySQL: Can’t create table (errno: 150)
- DATEDIFF function in Oracle
- GROUP BY and COUNT using ActiveRecord
- MySQL – Get row number on select
- Difference between EXISTS and IN in SQL?
- How to truncate the text returned for a column in a MySQL query
- How to implement LIMIT with SQL Server? [duplicate]
- What’s the best way to dedupe a table?
- Moving database with phpMyAdmin
- How To Write An Inner Join With WP Query
- How do I escape a table name or column name in SQL? esc_sql doesn’t do this
- Update user_login, user_nicename, and display_name
- Change sticky status of posts from phpMyAdmin
- Best Way to Merge a Dev and Live Site to Become a Staging Site?
- Needing to move content from postmeta to posts in sql [closed]
- How to import a Typo3 database to a wordpress site?
- Clean up very big and very dirty database
- How to delete ALL comments from certain category in WordPress database?
- How can I convert everything from category X to have post format Link
- Bulk delete WordPress Post and all metadata, etc using SQL query
- What steps do I need to take to install a local copy of a live website?
- Reset post IDs with all post meta
- How to Add or Change Post Title
- Why does DROP TABLE-ing the `wp_options` reset my user session?
- How to refactor DB queries for better TTFB in WordPress?
- query sql-table and change entities
- Duplicate WP Migration affecting site on separate domain?
- Backtick (MySQL norm) added to SQL Server Query causing error
- SQL query to check whether a meta key is set or not for a post in post_meta table
- Firebase with WordPress instead of SQL?