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.
8,754
questions
0
votes
1
answer
23
views
Can I avoid repeated code when nesting two case statements in Elm?
I'm converting a Maybe String into a Date. I've type aliased Date as Birthdate for readability.
birthdate_from_url : Url.Url -> Birthdate
birthdate_from_url url =
case url.query of
Just ...
1
vote
2
answers
24
views
Create a function to iterate over columns and create a new column each iteration in R
On occassion I get survey data with likert scale string items that I need to change to numeric in order to calculate basic descriptive statistics. In order to do this, I usually use the case_when ...
0
votes
1
answer
45
views
CASE expressions using values from different rows
I have below table
WITH TMP AS (
SELECT 'XX' AS AGG, 50 AS VALUE, 0 AS MONTH
UNION ALL
SELECT 'XX' AS AGG, 150 AS VALUE, 1 AS MONTH
UNION ALL
SELECT 'XX' AS AGG, 300 AS VALUE, 2 AS MONTH
UNION ALL
...
0
votes
0
answers
23
views
Oracle Query to retrieve only first & last name from a column using Case statement? [duplicate]
I need to write a oracle sql query using CASE Statement for the below.
The table “employee” contains columns: EID and Name with 4 values.
Below is Excepted Output with a new column "F_L_Name&...
0
votes
2
answers
20
views
using CASE WHEN statements in Microsoft Access [duplicate]
I know how to write CASE WHEN statements, but the problem here is translating them to Microsoft Access "language".
I've tried with IF statements but it didn't work, I've looked up how to use ...
-3
votes
0
answers
21
views
How to use cross apply in case statement [closed]
Anybody has any idea how can we use cross apply in case when exists statement.
Till now i have implemented this. But getting error. Please let me know how can I achieve this.
Select x.* , Case when ...
-2
votes
0
answers
18
views
DART Future Builder is not working with intended block, instead it is working and executing Default Case which is not valid
body: FutureBuilder(
future: Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.done:
...
0
votes
2
answers
24
views
Oracle subselect case
So, there are 2 tables
Table1 (Contains all articles,center,date 00000)
Tabla2 (Contains articles handwritten (that are also in Table1),center, date)
We have a procedure that every day compares ...
0
votes
1
answer
30
views
BASH Add up from one case /w another
How I can add up stats like atk, def... From class case /w warWeps case, wizWeps case and rangWeps...
ex. echo "Your char stats is ($class($atk) + ($warWeps($atk)"
#!/data/data/com.termux/...
0
votes
0
answers
24
views
Why do an error occur in the following group statement?
I have the following code:
select A.DATO, A.TRANS_KD, sum(A.CPU_MILLISEC), sum(A.ZIIP_MILLISEC),
A.time_dummy, A.BUSINESS_SYSTEM
from
(
Select DATO, TRANS_KD, CPU_MILLISEC, ZIIP_MILLISEC, ...
0
votes
1
answer
50
views
SQL Server: CASE statement, between two dates then this
I have a set of time series dates that I need to be able to sum by a date range. The problem is the date range isn't fixed, it changes a little month to month. I know the months beforehand so that's ...
0
votes
0
answers
16
views
Converting SQL Case to DAX measure
I need to convert a SQL Case statement to DAX measure, but some of the columns are measures themselves. Not sure to achieve this (
WHEN a.[field1] = 'Value'
AND b.[field2] IN('Value1','...
0
votes
1
answer
31
views
use distinct within case statement
I have a query that uses multiple left joins and trying to get a SUM of values from one of the joined columns.
SELECT
SUM( case when session.usersessionrun =1 then 1 else 0 end) ...
-1
votes
0
answers
36
views
Using Date of Birth to Calculate Age [duplicate]
I'm trying to create a table that uses an individual's date of birth to calculate their current age then use a CASE function to group by their age range. I'm not sure if this is the correct way to ...
0
votes
1
answer
24
views
RedShift - case statement failing CASE/WHEN must be type boolean, not type character varying;
trying to run below query but getting error. all fields in when are date
select
dt.*,
case when dt.search_mst_date then 'Daily'
when dt.search_mst_week then 'Weekly'
...
-1
votes
1
answer
28
views
Summing of Boolean 'Trues' in a Case Statement at MySQL
I would like to ask you whether I can count the 'Trues' in a Case statement.
t_1 As (
SELECT *,
-- Spot Guide not to be Empty
CASE
WHEN (total_spots_number <> 0 AND (spot1_availability IS ...
0
votes
0
answers
22
views
GDS - case argument using same value in multiple conditions
Trying to find a way to group two values within a field as "Two", while also having one of those grouped values displayed on its own. Below is the case I tried first, but it wouldn't combine ...
0
votes
1
answer
23
views
character case on a Loop
hope someone can help please. I was able to get the code but unable to display the characters similar to the input. I capitalized the input for comparison but output should be similar to the input. ...
0
votes
1
answer
18
views
Grouping Nested Query BY CASE OF ALIAS
I am trying to use a GROUP BY statement that would count each of the progress grades:
SELECT
with_avg.*,
CASE
when T_Points = Average then 'On Target'
when T_Points < Average then 'Above Target'
...
0
votes
1
answer
33
views
Two-part conditional sql statement
The statement below is querying a log table and I'm trying to get the max budget depending on the scenario if falls within.
Error message:
Expressions referencing the outer query are not supported ...
0
votes
1
answer
39
views
Subquery can return 1 column only
The purpose of this query would be to do a calculation based on if today's date is a weekday or a weekend and use it after with Union All, however I am getting
Msg 116 error:
Only one expression can ...
1
vote
2
answers
46
views
Ruby. How is the case equality method implemented in the class Class?
Is there any special Reason why the === and the == methods are implemented differently in the class Class?
"".class == String
#=> true
"".class === String
#=> false
4
votes
3
answers
139
views
Spring Data JPA sorting on additional column returned by query
I have a Table "team" with below structure:
Column
Type
Collation
Nullable
Default
id
uuid
not null
team_name
character varying(200)
not null
admin_group
uuid
not null
lead_group
...
0
votes
1
answer
23
views
SQLite Distinct With 2 Unique Column
I'm using SQLite. I want to get every data rows in 2 columns are unique.
This example data in order_transaction table:
date_transaction
customer
2022-05-11
Dio
2022-05-11
Dio
2022-05-11
Jotaro
...
1
vote
0
answers
39
views
Why is my function only being partially executed when embedded in a case statement?
I have a .conf file that I am calling in my main script, which contains a case statement.
In this file, I have a series of ssh commands that I am combining into a single variable/array/function (I've ...
0
votes
4
answers
53
views
Case function with an alias
I wish to use CASE statement with an alias that resulted of a quotient of two columns.
The code that I wrote is the follow, but it returns an error.
Could anyone help me with this?
SELECT TOP 5(ROUND(...
1
vote
1
answer
27
views
sqlite mark duplicates with true or false
I need to create a new column in my dataset (duplicate_name) that contains TRUE if there are more than one record for someone or FALSE otherwise. I found this code (I am working with sqlite):
SELECT *,...
-2
votes
0
answers
48
views
Case When Show All Rows In When
I am writing a query using case when and I'd like to have one of the when statements return a row even if there is no data for that statement/row.
For example:
SELECT
CASE
WHEN i.dept = 'HR' ...
0
votes
1
answer
28
views
R multiple case_when conditions and for loops
I'm trying to solve a complex problem, where I need to check conditions in 3 different data.frames to mutate the values in the main data frame.
I don't know if there is a smarter way, but I definitely ...
0
votes
0
answers
14
views
Count of a matching column with aggregation on another column
Assuming I have the following data:
---- ------ ------------
| id | text | timetamp |
---- ------ ------------
| 1 | X1 | 100.7 |
---- ------ ------------
| 2 | X2 | 100.2 |
---- ...
0
votes
1
answer
31
views
Count of matching column with aggregation on another column
Assuming I have the following data:
---- ------ ----------
| id | text | timetamp |
---- ------ ----------
| 1 | X | 100 |
---- ------ ----------
| 2 | X | 100 |
---- ------ -----...
0
votes
2
answers
36
views
Case in where using Parameter
I would appreatiate an advice. I need to filter table valued function on parameter. If Parametr is '', it should return all items. If parameter is not '', it should apply filter.
create FUNCTION [dbo]....
0
votes
2
answers
53
views
How to select objects if not exist between a period in Sqlite
I like to select those users who haven't filled out a form in the last 7 days but I'm stuck. The background: I am working on an app that lists the users who have filled out the form but I wrote it in ...
2
votes
1
answer
38
views
R create multiple variables with one condition
Is there a simpler way to write it,create multiple variables for one condition? like this
if am == 1 then do;
a="";
b="";
c=;
end;
else if am == 0 then do;
......
-1
votes
2
answers
47
views
Group By with multiple condition CASE WHEN in Sql Server
I have a table called DMIntegration like this with many dealerId:
DealerId | KPI | Value
----------------------------
001 1 Y
001 2 Y
001 3 Y
...
1
vote
1
answer
29
views
What is the type annotation for a case expression with multiple record types?
I have an update function in my Elm file.
It uses case expressions.
However, depending on the case, it is supposed to affect different parts of the model with different record types. Below is the code:...
-2
votes
1
answer
24
views
how can i get my case statement to return both prefer action and prefer comedy in my custom preference column if a person has both marked as 1
SELECT FirstName, LastName,
CASE
WHEN [Action] = '1' THEN 'Prefer Action'
WHEN Comedy = '1' THEN 'Prefer Comedy'
WHEN Drama = '1' THEN 'Prefer Drama'
WHEN Horror = '1' THEN 'Prefer Horror'
WHEN ...
2
votes
1
answer
26
views
How to add a column name inside a case_when when using mutate_all and across?
I have the following dataframe and I want to mutate all the columns in ENV dataframe to substitute some value with case_when function:
metrics <-
structure(list(var = c("SST", &...
1
vote
1
answer
28
views
sql conditional sum statement
The sql conditional sum statement below keeps throwing me an error and I'm not sure why.
The logic should create a flag when any of the underlying flags are 1, thus the sum >=1.
Error message: ...
0
votes
2
answers
31
views
How to return all rows in a column when using cross apply and DelimitedSplit8K_LEAD together in SQL Server?
This code works to return the info that I need from the column but IT IS ONLY RETURNING ONE ROW and I need it to return them all.
You can leverage the DelimitedSplit8K_LEAD function which you can read ...
-1
votes
0
answers
17
views
SQL CASE bracket in nested query
I wrote a sql query to fetch product details from two tables in a database. It uses nested CASE statements to satisfy the following question
Write a query to display (product_class_desc, product_id,
...
0
votes
0
answers
40
views
How can I have the Select Case choose between 2 Strings?
I created a Select Case with multiple locations that choose an Outlook form based on the user's location. I now have to add an additional String, as the users may have access to multiple mailboxes in ...
0
votes
1
answer
30
views
nested case when with count and math expression
how can I achieve this result below?
id
id_status
rate
25
X
62.5%
15
Y
37.5%
having tried this
SELECT
COUNT(tab.id) AS id,
tab.status AS id_status,
(CASE
WHEN tab.status = 'X' THEN (...
0
votes
0
answers
29
views
Hive Case statement date conditions not working
Hi I'm using hive I need to add a case statement with multiple conditions for jira_label below.
Basically, if jira_label has a null value and the jira_issue_due_date is less than the current date then ...
0
votes
1
answer
19
views
Is there a way to do a case_when in a for loop with multiple statements being checked in R?
I am trying to assign values to a variable given the value of three other variables in my data. The structure I have currently is:
df <- df %>% mutate(i_prob = case_when(
segment == "NS&...
-1
votes
0
answers
34
views
SQL Query Order by and Sort by in Nested Case Got this Error - A constant expression was encountered in the ORDER BY list, position 2
I want to do a dynamic sort by, order by using the CASE statement. I tried all the materials available online but still, i couldn't find the solution.
Explanation -
If Order by is "ASC" and ...
0
votes
0
answers
11
views
Azure DevOps – automated test cases: How to remove unwanted test case associations
I have a Visual Studio project with a Selenium test. For the test, I can select the “Associate to Test Case” option, but this displays a list of test case associations and it seems that I can only add ...
0
votes
1
answer
28
views
SQL Case WHERE condition, if condition passes check if value is not null
I cannot figure out how to add the last condition.
This is part of dynamic code + cursor. Cursor consists of a list of table columns. I am comparing values in two tables that are identical in their ...
0
votes
1
answer
31
views
purrr::when() doesn't evaluate first condition
Apart from the more common purrr::case_when that elegantly performs a vectorised if-else statement, there is less known variant purrr::when which is non-vectorised yet still useful in many scenarios. ...
-1
votes
0
answers
12
views
Azure DevOps – automated test cases: How to share a test library by multiple test cases
I have a Visual Studio project with a Selenium test. I would like to associate this test with multiple test cases in Azure DevOps and I would like the Selenium test to be able to distinguish by which ...