Arithmetic overflow error converting nvarchar to data type numeric in case query

I am trying to show the number of quotes won as a percentage of the total number of quotes in a time frame. For example. I have a total of 294 quotes and 173 of them are won. The result I am looking …

SQL: Change the value of a column in function of another

I get a table from SQL that I put whitin a winform’s datagridview. I just want to change the value of my last column in funtion of another. Here is the example: I have 4 columns : ID / Price / …

Case expression with Boolean from PostgreSQL to SQL Server

I am translating a query from PostgreSQL to SQL Server. I didn’t write the query in PostgreSQL and it’s quite complicated for my knowledge so i don’t understand every piece of it. From my understand: …

How i want make 3 rows of the same primary key into 1 row by checking and choose its value using case

For example here, from this table key | status 1001 | A 1001 | D 1001 | C the hierarchy will be C>D>A If the the stats contain C as the value, the person status will become C in one row. …

How to use CASE WHEN in PostgreSQL without adding values to aggregation and GROUP BY?

I need to take one timestamp if my condition is right and other value, if not. I made such condition: CASE WHEN tr.type = ‘deposit’ THEN tr.timestamp::date ELSE tr.status_last_change_timestamp::date …

Why am I getting a CASE error when in Data Studio?

I’m trying to convert a four-digit numerical code to a four-digit (one letter + 3 numbers) with a CASE clause in Data Studio. The four-digit numerical code is being pulled out of a Sheets file. I keep …

How can I count rows into more than one ‘then’ of a Postgres searched case expression? (reporting)

Background I have a Postgres 11 database running on RDS. I need to produce a report which shows counts of events over a certain period, grouping, renaming, and counting them based on description …

How to return only one row per course

I am trying to return a list of course IDs that contain three components: assignments, discussions, and a syllabus. I want my results to have only one row per course ID with either Y’s or N’s …

How to put Case in Where Statement for Oracle SQL

For the query below, I’m trying to pull a specific date range depending on the current day of the month. If it’s the 20th or less (e.g. “2/7/2020”) then I want the date range for January. Otherwise, I …

Convert result of CASE Expression to a number in Oracle SQL

I have the following select query. I want to convert it from string into a number. If I wrap a TO_NUMBER around the case expression, I get expression must have same datatype as corresponding …