I have a table as follows i want to increment the datetime by 1minute for each id so the outcome should look like how can i achieve this in an update statement all at once? since i have like 100 rows Answer You can use an updatable CTE: db<>fiddle
Tag: sql-server
How to Convert Hours, minutes and seconds (HH:mm:ss) to minutes and seconds (mm:ss) in SQL
Suppose I have 2hrs, 47minutes and 10 second (02:47:10) which is in hh:mm:ss format as a value in Time column. I would like to convert it to minutes and seconds only (mm:ss). Hence the result should be 167minutes and 10 secs in sql. I have tried using the code The result was 167.166666. My desired output shou…
SQL Server – current inventory with physical count
I feel as though I’m missing something extremely fundamental that should be obvious. I’m basically trying to take the below data and calculate a fifth column: Inventory_Current. Example data: DateStamp ProductID Inventory_Change Inventory_Count 2021-07-01 100 -300 100000 2021-07-01 200 -700 50000 …
Calculating distance using geometry of x and y location in SQL
I’m using SQL Server and I need to calculate the distance between the x and y of a frame and the previous x and y of a frame where the day, team, and member are all the same. Currently, I have this code that works but doesn’t accomplish what I need. I’m getting every distance permutation of …
Insertion of dynamic values to specific colums using SQL
I’m trying to insert a new row into a table, but one column’s value insertion is dependent on a specific rule. So far I get an error because SQL doesn’t support my way and I have no idea what to do: How can I insert the max(RNFIL170.SEDER_HATZAGA)+1 into RNFIL170 ? Answer use INSERT INTO …
SQL server Change Column datatype on 1K million records
I am facing the column length issue in my table and I want to change column type to big int from int and table rows around 1K million records but when ever I tried to change data type it is taking to much time and it is eating my machine all space, what is best way and fast way to
Display individual elements from grouped rows on same row
I want to both group some rows together but return 1 column of the individual rows from the group onto the same line as well, probably easiest to show with an example…. Original Data Grouped by rDate, track, AVG(odds) Desired output, grouped with average odds but with individual odds added to grouped ro…
Error when SQL Server grand total comes out on first row instead of at table end
The following query gets row and column totals. When I add ORDER BY, the column total appears in the first row instead of the bottom row. What could be your suggested solution? Answer you can use grouping which returns 1 if the column is part of aggregation and you can use it in your order by:
Microsoft SQL Server : how to filter out results of a 2nd query from the first query
Let’s say I have data that looks like this: I have some records that are retired and some that are active. The problem is some of my records have both retired and active rows. I only want records that do not have an active row. So in this example despite the fact that Greg has 2 retired rows. The fact
How to update one row that has max value in column (SQL Server)
I am trying to update the Rows that have the Max score with the value of ‘Yes’ in the Text1 column. This is straightforward except when there are multiple rows with the max score. If they have the same score, I just want to select the top row to have the value ‘Yes’. Only one row with …