I have a query that is structured like this: For the case of it returning no values, I want it to return null-values instead of a empty row. How would I achieve this? I was not able to make commonly suggested solutions work, because of the pivot. E: The result I get: No row returned: The result I want: One
Tag: sql
SQL Database Project – Deploy script in wrong order
At the moment I have a SQL Project ready to be deployed (Its like-for-like with the prod version). However, when generating the deployment script – objects such as the stored procedures are coming up first in the deployment scripts; therefore the script is failing as the dependent objects (tables, funct…
Compare two similar columns in different tables and result in separate output
I have a two tables with same column names. I would like to compare two columns . For eg:- Table 1 has server and IP address like Table 2:- Desired output:- Answer It looks like a FULL JOIN is what you need here. Sample data Query Result
SQL replace and calculate character length and replace again
I want to do an update on a Firebird table. So far not a problem: Before the update statement my params look like this: After my update the params look like this: So far it’s ok. But the frontend program can not handle this because there is a checksum in the params. The value s:91 is the character lengt…
Stored procedure runs correctly only sometimes
My problem is: I have a stored procedure that only sometimes runs correctly, sometimes it does not run at all and sometimes partially (some rows where inserted in the table bot not all). I use lazarus …
Split Row and Paste to Different Tables Based on Column
I have a table like this. Table is populated each time an order is complete. One order can have one or many compartments. Please help write an SQL script that takes the above and splits it into two new tables like so: Table 1 Table 2 I’ve tried using the DISTINCT command as suggested; Which returns the …
Creating extra columns based on condition (Case When Sum)
I have survey table where someone is asked roughly 5 questions. 4 of those questions are the same questions, but the options to their answers are different since they were to understand their purchase. Here are the questions: The goal is to create four extra columns based on their answer and they will be assi…
Join two columns as a date in sql
I am currently working with a report through Microsoft Query and I ran into this problem where I need to calculate the total amount of money for the past year. The table looks like this: How would you calculate the total amount from 02-2019 to 02-2020 for the item number 12345? Answer Assuming that you are ru…
Having trouble wrapping my head around how to write a particular loop
I am querying a SQL database to return open work order operations. My query is producing the Work Order number, operation status and due date. I am trying to figure out how to iterate through the array that is returned and: Gather the sum of operations due within a week Gather the sum of operations due in the…
Can’t insert multiple rows in SQL Server Manager Express 2005
I have a Table HORAS_X with ID_HORA(int), ID_ZONA(int), DESCRIPCION(nvarchar), COMIDA(bit), META(int), NUMERO(int). I can insert a single row like: INSERT INTO HORA_X (ID_HORA,ID_ZONA,…