Skip to content
Advertisement

Tag: case

Using a subquery in a case statement in a where clause

I want to select different results (from a temp table) based on what a certain parameter is set to in the query. I want to exclude certain inventory SKUs if a particular warehouse is selected. I am getting this error, unfortunately. Msg 512, Level 16, State 1, Line 310 Subquery returned more than 1 value. This is not permitted when

Oracle SQL – implement logic based on CASE expression result

I have following query which returns me of percentage of rows with at least one NULL in any of columns: Query works fine to me and I am getting valid result. But I need to do further action in tablec, based on percentage calculated in my SELECT statement. If percentage of rows with NULL is below 30% I need to

Before/After Difference for a flexible Date (Case)

i have a little problem with a case. I output two date fields (yyyy-mm-dd). the date changes and is flexible. not every entry has the same date fields. I take one date field as an fixed point. If the Date is 4 months before the date, a ‘V’ should be the output. if it is behind it, an ‘N’ should

SQL CASE that matches value or uses LIKE ‘%’

I’m trying to do a wildcard retrieve if a defined variable is blank. But I can’t figure out the correct syntax. Answer It is as simple as this: The expression NULLIF(x, ”) will convert ” to null. Then we take advantage of how null comparison works: If @customerID is not null then first condition will be true only for exact

Access alias in CASE statement

I am trying to create a column called DateStartedStatus that utilizes a previously aliased column to compute its value. It should use CurrentStatus to output a value and an error is showing that says “Invalid column name ‘CurrentStatus'”. How can I access that alias in the below case statement? Answer Using subqueries like this Do not worry, subquery will not

Advertisement