I have data that looks like: User Start_Time End_Time ————————————————- A 2018-12-05 08:30:00 2018-12-05 09:45:00 B 2018-12-05 09:30:00 …
Tag: sql-server
OFFSET doesn’t work when a column is sorted with all NULLs
I don’t understand why the OFFSET clause doesn’t work when I’m retrieving a table sorted by a column that contains all NULL values? For example, let’s say I have a table People with ID, Gender, and Race columns. The Race column contains all NULL values. When I run these to queries, why…
Why is my calculating a percentage not working correctly when I am dividing?
I am trying to see what percentage of customers paying LL and the percentage of customers that are paying LP. For example I have 1 customer in LL and 1 in LP so percentage should be 50% in Cust_LL_Pct …
Extracting Dates based on Months
I have a table in an MSSQL database that lists when students start a programme. The academic year runs from August to July. Where a student starts on 01 Sep 2019 I want to show that they started in …
How do I include an additional non-aggregated column for each of my in my PIVOT values?
I have the following code fragment which gives me the current results below. I’m attempting to add an additional column for each of my pivoted values in order to include the lastview data for each of …
Moving all rows with a certain index into a single row
I have a table with as structure like the following, with an unknown number of rows with each group index. Group || PropertyA || PropertyB || PropertyC ============================================ …
SQL Query on Json object inside multiple JSON objects
I have the below Json string. I need to write a query to get the TP records. Without providing the index value, we need get the result. How do I query to get the TP values. Expected Result: Answer You can use OPENJSON function containing WITH Clause added as many CROSS APPLY Clause as upto see all sub-arrays …
Query problem-getting wrong result when a condition or a set of data included
I have bug in my query, but I have no idea what happen. So there is 3 tables. table 1 name grade min max a b c d e table 2 fullname name min max a a123 1 10 bbbb b …
SQL select row with max value or distinct value and sum all
I have the following data that is returned to me. I need to get a distinct or max sum of all the commission by taxid for a single repnbr. The ‘qtrlycommrep’ column is the value I’m trying to get to, …
For SQL Server database getting “com.microsoft.sqlserver.jdbc.SQLServerException:The statement must be executed before any results can be obtained.”
I am getting above error when trying to perform insert operation from java application using JDBCTemplate. org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; The statement must be executed before any results c…