Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

case-when

how to put nested case-when condition in postgresql query

December 13, 2023 by Tarik

CASE … WHEN … END is an expression. It can be nested like any other expression. CASE WHEN condition THEN CASE WHEN othercondition THEN …. END END

Categories postgresql Tags case-when, if-statement, nested, postgresql Leave a comment

Execution order of WHEN clauses in a CASE statement

September 12, 2023 by Tarik

The value that is returned will be the value of the THEN expression for the earliest WHEN clause (textually) that matches. That does mean that if your line 2 conditions are met, the result will be A2. But, if your THEN expressions were more complex than just literal values, some of the work to evaluate … Read more

Categories sql Tags case, case-when, sql, sybase Leave a comment

SQL Server CASE .. WHEN .. IN statement

September 8, 2023 by Tarik

CASE AlarmEventTransactions.DeviceID should just be CASE. You are mixing the 2 forms of the CASE expression.

Categories sql Tags case-when, sql, sql-server, sql-server-2005 Leave a comment

How can I SELECT multiple columns within a CASE WHEN on SQL Server?

August 31, 2023 by Tarik

The problem is that the CASE statement won’t work in the way you’re trying to use it. You can only use it to switch the value of one field in a query. If I understand what you’re trying to do, you might need this: SELECT ActivityID, FieldName = CASE WHEN ActivityTypeID <> 2 THEN (Some … Read more

Categories sql-server Tags case-when, select, sql-server Leave a comment

How do I use T-SQL’s Case/When?

April 27, 2023 by Tarik

SELECT CASE WHEN xyz.something = 1 THEN ‘SOMETEXT’ WHEN xyz.somethingelse = 1 THEN ‘SOMEOTHERTEXT’ WHEN xyz.somethingelseagain = 2 THEN ‘SOMEOTHERTEXTGOESHERE’ ELSE ‘SOMETHING UNKNOWN’ END AS ColumnName;

Categories tsql Tags case-when, tsql Leave a comment

Can dplyr package be used for conditional mutating?

October 12, 2022 by Tarik

Use ifelse df %>% mutate(g = ifelse(a == 2 | a == 5 | a == 7 | (a == 1 & b == 4), 2, ifelse(a == 0 | a == 1 | a == 4 | a == 3 | c == 4, 3, NA))) Added – if_else: Note that in dplyr 0.5 … Read more

Categories r Tags case-when, dplyr, if-statement, r Leave a comment

OR is not supported with CASE Statement in SQL Server

September 11, 2022 by Tarik

That format requires you to use either: CASE ebv.db_no WHEN 22978 THEN ‘WECS 9500’ WHEN 23218 THEN ‘WECS 9500’ WHEN 23219 THEN ‘WECS 9500’ ELSE ‘WECS 9520’ END as wecs_system Otherwise, use: CASE WHEN ebv.db_no IN (22978, 23218, 23219) THEN ‘WECS 9500’ ELSE ‘WECS 9520’ END as wecs_system

Categories sql Tags case, case-when, sql, sql-server, tsql Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa