Not sure how to create a SQL formula that subtracts timestamps in the same column to get the seconds between actions - sql

Need assistance with creating a "datediff" type of formula.
I have timestamps in the {incilog} table, in different rows across the same column {incilog.timestamp} that I need to subtract from one another, but only if the {incilog.transtype} equals "TR" from the row that has the {incilog.transtype} equal "FPS".
Logic is: If {incilog.transtype} equals "TR" and {incilog.transtype} equals "FPS", then subtract {incilog.timestamp} from {inciog.timestamp} in the corresponding row.
Basically, I need to get how many seconds it took from "TR" to "FPS".
THANK YOU FOR YOUR TIME AND ASSISTANCE!
EXAMPLE OF DATA
timestamp
inci_id
transtype
descript
8/22/2022 12:14:46 AM
2022264051
TR
Time Received
8/22/2022 12:17:00 AM
2022264051
FPS
Fire Pri. Started

Related

Microsoft Access- How to create dynamic variables that queries a selection of Columns

Example Data Picture
My main data table is constructed in the following way:
1.State
2.Product
3.Account Name
4.Jan-20
5.Feb-20
.
.
.
N.)Recent Month- Recent Year
My goal is to get 6 total sums based on 6 different contiguous that are user selected. For example, if someone wanted the value of an Account Given a State and Product for FY-2020, they would sum columns 4 to column 15 (Twelve Months).
I am going to be running joins and queries off of the State, Product, Account combinations (first three columns), but I need to create a method to sum the Data table given a list of Column Numbers.
At this point, I am not looking to put non-contiguous columns in a selected Time Period (i.e. all time period selections will be from Col.Beg_TPn to and including Col.End_TPn). The Data Table houses monthly data that will have one new column every month. The Column Number should stay consistent as we are not looking back further than FY-2020.
This a much easier problem in Excel as you can do a simple SumIfs with an Index of the Column Range as the SumRange and then you filter on Columns 1,2,3. My data table is about 30,000 rows, so Excel freezes on me when could calculations and functions on the entire data set.
What is the best way to go about this in Microsoft Access? Ideally, I would like to create a CTE_TimePeriodTotals that houses the First 3 Columns (State,Product,Account) and then 6 TP Columns (tp-1,tp-2...) that holds the sum of each time period for each row based on the Time Period Column Starts and Time Period Column End.

Wanting a datediff formula to get the difference in seconds between each trasntype

Was hoping to get some insight into what I should include in a Datediff formula to calculate the difference in time between columns and rows. Using the "timestamp" column as the date, and the "transtype" column as the modifier. So something along the lines of "timestamp (TR) - Timestamp (FIN)". I've attached a screenshot for what the data looks like.
I'm essentially trying to find a formula that calculates the time between each "transaction" or "transtype", per "incident" or "inci_id".
Thank you for your time and assistance.
Data example

Subtracting Date/Time from two different tables in SQL

I have two tables with a time column (year-day-month hr:min:sec)
Let's say name of table 1 is plc and column name Collect
Name of table2 is Adm and column name Disc
I want to subtract the time of Collect (2005-01-03 18:10:05) from the disc column (2005-01-03 20:15:10) in day, hours, minutes.
Any help would be appreciated!
I would surely go for the datediff function.
Have a look at this link:
https://msdn.microsoft.com/en-us/library/ms189794(v=sql.90).aspx
If you want, you can select difference in minutes, and then, with the minutes, calculate the days and hours
Use Date() or Datepart() function to fetch the specific part of the date and subtract the two.
You can get more details of the above two at the following link:
https://learn.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql

Excel logic - matching columns

My situation is the following:
The 'Day' column is 1 to 365, and each day is repeated 24 times (for the 24 hours). Each day and hour together have a Degree value, represented by the B column. I need to multiple the B column with the E column everytime A column matches D (eg. B2*E2, B3*E2, B4*E2, B7*E3).
How can I do that? I'm really confused here.
Thank you
Using your shown example, in cell C2 and copied down:
=B2*VLOOKUP(A2,$D$2:$E$366,2,FALSE)
Two ways:
VLOOKUP(A2,$D$2:$E$366,2,FALSE)*B2
SUMPRODUCT(B2*($D$2:$D$366=A2)*$E$2:$E366)

Date Time is not being pulled from the database where numbers from the same column are being pulled in my report

I have two columns:
The first column can only have values 1 or 2.
if 1, then my second column has a number.
if 2, then my second column has a Date Time -( something like this 1/1/2014 12:00:00 AM ).
What I am doing:
I have a tablix with 2 columns..
First column is named a and second is named b
under first I want numbers and under second I want the date time. Basically want to split the second column based on what's on first column i.e. 1 or 2
I have used expressions:
=IIF(Fields!first_column.Value=1, Fields!second_column.Value,nothing)
and for second
=IIF(Fields!first_column.Value=2, Fields!Second_column.Value,nothing)
it works prefectly for the number and gives result whereas the column where there should be the date time gives blank with no results. I have tried switching them, using numbers on both and using dates on both column. but every attempt the numbers work the date time doesnt work.
If I was too wordy and didnt make sense, please let me know and I can answer your specific qustions.
Thank you.