Skip to content

Tag: case

SQL: Creating quarter values based off conditional statements

I have the following table: jan feb mar apr may jun jul aug sep oct nov dec 322 44 1222 These are invoice amount columns. They’re based off of the months of the year. What I’m trying to do is make a new column called execution window that will have different quarter values depending on where the amounts show up

A better way to get the last character

I have been working in an exercise, I have 2 values (one with 9 characters and the other with 8) and I have to show 3 columns. The original number The number without the last character Only the last character The Query works but I would like to know a way to improve how I get the last column, I

Multiple conditions in CASE WHEN statement

I’m working in SQL (Amazon Redshift) with Recruitment data where each applicant has multiple sources, which I’ve split into different columns called source_1, source_2, and source_3, along with a number_of_sources column to record how many sources that applicant has. We want each applicant to only have one source, and have certain rules to follow in how to select which source,

SQL divide row by row with the same column by using CASE

I want to create a new column which is to calculate the percentage, I know it can use subquery to do that, but is it possible to use CASE to do this? If using CASE how is the logic? Column A Column B Column C New Column that i want to create 2022-01-01 M0 72 72 * 100 / 72

SQL Server => How to use “case when” on multiple column to show a formula result based on a condition in the same line

I’m trying to provide an overall result of a formula ([CALCULATION]) and then in two extra columns ([NO_TENURE] & [TENURE]) the same calculation but using “CASE WHEN” to filter the information based on another column called [TENURE], everything in one single line like this: Right now is being shown this way: This is the code I’m using: I really appreciate