Questions tagged [case]
The case tag has no summary.
191 questions
-1 votes
1 answer
95 views
Oracle Violates Short-circuit in CASE Statement
Problem I am well aware that SQL is a declarative language and does not enforce short-circuiting. Oracle, on the other hand, explicitly states that short-circuiting takes place for CASE statements. I ...
0 votes
1 answer
152 views
How to Avoid Duplicates with multiple joins and multiple case statements
I have a query which has multiple joins and need case statements for multiple columns to get the correct data. Although I can manage to get the data, it creates a lot of duplicate rows. Seems like 1 ...
1 vote
1 answer
678 views
Regex help in Snowflake
I am trying to write a regex that can replace '[', ']' and '].' with '_' and in cases where ']' is the last character it should be replaced with '' but I am struggling to come up with a regex for it ...
0 votes
0 answers
30 views
MySQL case sensitivity setting
Does anyone know the file name or path where I can change the lower_case_tables_names value on the latest version of MySQL Windows 11?
0 votes
2 answers
898 views
Comparing 2 count columns with case
I have 2 tables, size and cost. My query does a count with a greater than comparison of cost and counts different sizes. table1: size u table2: cred t Here is my query: select u.size as size ,...
-1 votes
1 answer
69 views
how to GROUP BY so that not all results are grouped
When I use my query to select all data from the table I have a problem with the custnumber field. If custnumber is returned within the same month then it should group the results but only then. This ...
0 votes
1 answer
167 views
Set variable on multiple case within each group
Say I have below table cis aid cid apid ntime buid flg jid 30 1208 229067737 1026 9 DDDD400C 0 0 30 1209 229067737 1026 11 DDDD400C 0 0 30 0 229067737 1026 12 DDDD400C 1 100 30 1210 229067737 1026 13 ...
2 votes
1 answer
133 views
MySQL - multiple CASE ordering with joined table
I have two tables: EVENTS ID Name 1 First event 2 Second event 3 Third event 4 Fourth event 5 Fifth event EVENTS_META ID EventID MetaKey MetaValue 1 2 date_expired 2023-02-09 00:00:00 2 2 date_expired ...
0 votes
2 answers
213 views
SQL multiple condition case when
SQL Case When - I have a column with job status options B & D. I want to create a case when SQL statement that will check and retrieve employee IDs with both statuses in the column. In thise case ...
1 vote
1 answer
368 views
Problem with case statement and dynamic table name
I have the following case statement case %1$s::text when ''lookup_relation_job'' then case %1$s.relation when ''followers'' then ''get-followers'' when ''following'' then ''get-...
0 votes
0 answers
490 views
Replacing Part of a string within a group Concat
I have part of a string that I would like to remove when selecting. The Problem is that there are a few pieces within the string that changes. This is what I have so far. Select GROUP_CONCAT(...
0 votes
1 answer
1k views
How to conditionally return multiple different columns in sqlite?
I am trying to return multiple columns only if a condition matches, else, return something else. Using Sqlite3, my understanding is that the way to do this is using CASE, so something like this: ...
0 votes
2 answers
193 views
Limit my ticker count to maximum 12 Months
I'm trying to write a case expression where it looks at the due date and if it has passed chooses the upcoming or closest due date. Now due to certain database restriction I have to do this manually. ...
-1 votes
2 answers
3k views
SQL Server: left join resulting in multiple rows, want each row result in separate column in result
I need some logic help with a complex join situation. Here is an overall idea of the 3 tables I am working with Table 1: ID Number Type 1 A1 A2 Table 2: ID Number Type 1 ID Number Type 2 A1 B1 A1 B2 ...
1 vote
1 answer
2k views
How to use a JOIN inside a CASE expression?
I have four tables like this: company: id companyContactID customerID companyTeamID 1 12 21 54 2 14 12 78 document_associated_company: id companyID documentID 1 2 98 2 1 12 document id documentTypeID ...