Fairly new to SQL here… I am trying to get an ‘after update’ trigger in SQL Server to update a column (rig_ident) whenever another column (rig_id) is updated. rig_ident is found by searching the …
Tag: sql-server
diffrent serial no for each ID in MSSQL
I have a table where I Have 2 ids table is like ID Date Shift(hr) serial no 54 11/10/2020 2 1 54 10/10/2020 5 2 …
DataTable ‘Table’ already belongs to this DataSet – on a new DataSet?
I have a function that executes SQL queries and returns a generic DataSet of the query results. This function has been working for years in many applications, but today with a specific query I am getting “Error executing [select top (1) RecordId, SourceCID, SourceID, CaseID, DisposeRequestedDate, Dispos…
Set two decimal places after AVG function inside PIVOT
The output keeps being 95.000000 I tried using AVG( CAST(Grades AS Decimal(10,2) ) ) inside the pivot, and it keeps returning a syntax error about (. Tried using CAST AS DECIMAL inside the FROM subquery, but it just keeps putting the same 00000 output. CAST AS FLOAT works but I need two decimal places and it …
SQL Date Filter: Return results when start date = end date
:startDate and :endDate are given value from html input and passed as parameters with AJAX. I want to return notifications BETWEEN :startDate and :endDate, but also return a notification if startDate …
Getting SUM of ‘x’ consecutive values where x is an integer from another row
I am trying to code in Microsoft SQL Server Management Studio. This is SQL. I have to get the sum of x previous consecutive rows where x is based on a number in another row. For Example: Example 1: …
Dynamically Insert into Table A Based on Row_Num from Table B
I’ve condensed some data into TableB which looks like the following: There are 2000 unique rows in total, Row_Num from 1 to 2000, and every AreaID in this table is naturally unique as well. I now want to insert into a blank table, TableA, which has the following columns: The insert statement I want to u…
Insert a NEW Row using a Single Value from LAST row with Stored Procedure
Please refer to the screen captures below. I am trying to create a stored procedure in SQL Server 2014 that does the following: Sets the “Complete” BIT in the LAST record (e.g. row #1062) to TRUE Takes a the “DateTo” value from the LAST record (highlighted in yellow) and INSERTS it int…
TSQL – how can I sum values except absolutes
I would like to sum values in my table, except the ones that are absolute (field absolute, value = 1). If that’s the case, the summing should reset. Example: Regular SUM() would return (4+7+3=) 14. But in this example it should reset at value 7, which makes a sum of (7+3=) 10. How can I make this work? …
Retrieve data from two different rows in a single SQL query?
I’ve a table with the following data and I need to find the number of minutes between two jobs (Say A and C). The following query works but wondering, if there is a simpler way to achieve the same. Goal is to achieve, the difference between start time and end time of two jobs. Answer I can interpret you…