I want to consolidate records based on a time gap of 5 minutes between the current row-end date and the next row start date. How can I achieve this T-SQL? Before Consolidation, the table is like below – It should look like below after consolidation – Answer This is a type of gaps-and-islands probl…
Tag: sql-server
Updating a table in SQL Server with information from another table
I have a “claims” table. Each claim has a client attached to it which is represented by a few letters “ABED”. For some reason, the actual clientID is nowhere to be found in the claims table so I want to fix this. The “Clients” table DOES contain both the code AND clientID. …
Why do I get a conversion failed error when I use my attribute on my WHERE clause but it works when I don’t?
Why is my query returning a result when I run the following query: SELECT MAX(CAST(IssueDate as Date)) FROM (SELECT IssueDate FROM [Transient].[Commissions_TIB] WHERE ISDATE(issuedate) = 1 …
STUFF function truncated result
I am trying to generate dynamic sql by querying a table and using the STUFF function and returning the results into a variable (DECLARE @dynamic_query NVARCHAR(max)). My problem is that the results returned by the STUFF function are truncated/incomplete. The content of @dynamic_query will be cut short. I can&…
How to insert values into the following table by incrementing the date column by 1 day for the next 23 days?
I am using SQL Server 2014. I have a table names T1 (extract shown below): I need to update table T1 for period 2020-10-13 to 2020-11-04 with the following logic: All rows to be appended to the table will have the same values as those for ReviewDate on 2020-10-12 except the ReviewDate which will increment by …
Dynamic columns from two tables
i need some help. I would like to combine two tables in sql with dynamical columns. Here my thoughts: Table one: Example Table jrincidents Table two: Example Table jrusers reporting like i don’t know how to dynamically add the steplabels from table jrincidents as columns of jrusers if where processname …
Join Tables to return 1 or 0 based on multiple conditions
I am working on a project management website and have been asked for a new feature in a review meeting section. A meeting is held to determine whether to proceed to the next phase, and I need to maintain a list of who attended each phase review meeting. I need to write an SQL query to return all people, with
Indexing an SQL table by datetime that is scaling
I have a large table that gets anywhere from 1-3 new entries per minute. I need to be able to find records at specific times which I can do by using a SELECT statement but it’s incredibly slow. Lets say the table looks like this: I’m trying to get data like this: I also need to get data like this:
datetime.datetime conversion to datetime
I have defined a column in SQL Server as ldate with datetime data type and accepting null values. I’m trying to send data from my local machine using python and pyodbc. I have date like 20-01-2015 in string format. When I try to send data it throws an error: pyodbc.DataError: (‘22007’, ̵…
Calculate percentage using SQL
I am trying to find how I can calculate Percentage from table below From the above table, I am hoping to get the data with percentage like below. However my SQL statement below returns all percentage …