I am working on a report where i have receiveddt field, finalreportdt field, and a calculated turnaround time(TAT) column at the end.
I am trying to write an IIF expression in the TAT column that calcs datediff between the receiveddt & finalreportdt in hours if there is a finalreportdt value generated. If the finalreportdt is blank, datediff must be between the receiveddt and the current date and time.
I've got the receiveddt to current dt expression figured out
DateDiff(DateInterval.Hour,min(Fields!u_receiveddt.Value), Now())
and the datediff for the finalreportdt-receiveddt is straightforward. I'm hitting a wall with combining the two statements.
Here's my most recent try:
=IIF(ISNOTHING(Fields!finalreportdt.Value),
(DateDiff(DateInterval.Hour,min(Fields!u_receiveddt.Value)
, Now()))
,(DateDiff(DateInterval.Hour,min(Fields!u_receiveddt.Value),Fields!finalreportdt.Value)
When i try to run the report, i get an error. Anyone know a better way or see my mistake?
Related
I am having a hard time trying to find something that would be equivalent to YEARFRAC (Excel) for Teradata. I messed around with the below, but want I want it to display the fraction of the year. So instead of 37 I would want to see 37.033. If possible would like it to account for leap years so wouldn't want to just divide it by 365. Any help would be greatly appreciated!
SELECT (CURRENT_DATE - CAST('1985-05-01' AS DATE)) YEAR
There is no direct function to get the desired output.
Excel YEARFRAC method uses different logic to calculate the output based on the optional parameter basis.
Syntax YEARFRAC(start_date, end_date, [basis])
Considering the basis parameter as 0 or omitted, you can achieve it in Teradata using below query.
SELECT
DATE'2022-05-13' AS Till_Date
,DATE'1985-05-01' AS From_Date
,(Till_Date - From_Date) YEAR TO MONTH AS Year_To_Month
,EXTRACT(YEAR FROM Year_To_Month)
+EXTRACT(MONTH FROM Year_To_Month)*30.0000/360
+( EXTRACT(DAY FROM Till_Date)-EXTRACT(DAY FROM From_Date))*1.0000/360 AS YEARFRAC
The basis parameter with 0 or omitted uses a 30/360 format to calculate the difference.
You can find more details about the YEARFRAC logic in below link.
https://support.microsoft.com/en-us/office/yearfrac-function-3844141e-c76d-4143-82b6-208454ddc6a8
I was reading through a couple of older posts and tried to apply the same logic to my question, I need to extract 13 months of data broken down per month, I would also like to apply the data to relevant headers... any suggestions. Please see code below and error received.
SELECT ST.TXDATE, ST.CODE, ST.QUANTITY
FROM StocTran ST
WHERE ST.TXDATE >= DATEADD(MONTH, -13, CAST(GETDATE() AS DATE))
ORDER BY ST.TXDATE
ERROR: [Elevate Software][DBISAM] DBISAM Engine Error # 11949 SQL
parsing error - Expected end of statement but instead found ( in
SELECT SQL statement at line 3, column 27 Error Code: 11949
DATEADD is a function in MS's TransactSQL for Sql Server. I do not know that DBIsam supports it, and it is not listed in DBIsam's list of supported functions here:
https://www.elevatesoft.com/manual?action=viewtopic&id=dbisam4&product=delphi&version=7&topic=functions
Generally, date functions are not portable across different SQL engines, and from that list, one possibility might be to use the EXTRACT function instead:
The EXTRACT function returns a specific value from a date, time, or timestamp value. The syntax is as follows:
EXTRACT(extract_value
FROM column_reference or expression)
EXTRACT(extract_value,
column_reference or expression)
Use EXTRACT to return the year, month, week, day of week, day, hours, minutes, seconds, or milliseconds from a date, time, or timestamp column. EXTRACT returns the value for the specified element as an integer.
The extract_value parameter may contain any one of the specifiers:
YEAR
MONTH
WEEK
DAYOFWEEK
DAYOFYEAR
DAY
HOUR
MINUTE
SECOND
MSECOND
Even if you are in a hurry, I strngly recommend that you study that page carefully.
UPDATE: From googling dbisam dateadd it looks like Elevate don't have a good answer for an equivalent to DATEADD. One of the hits is this thread:
https://www.sqlservercentral.com/Forums/Topic173627-169-1.aspx
which suggested an alternative way to do it using Delphi's built-in date functions (like IncMonth which I suggested you use in an answer to another q. Basically, you would calculate the start- and end-dates of a range of dates, then convert them to strings to construct a WHERE clause with a column date (from your db) which is equal to or greater than the start date and less or equal to the end date.
I am trying to achieve the following in SSRS:
Basically, to calculate aging column whenever my Date Field in Status B grouping is NULL.
Would anyone be able to help please? or point to a question that is similar?
(I've tried searching but I can't seem to get something that I can grasp)
edit #1 (20160712) - The data I have is row based :
Do this in the SQL that is called by your report:
Make the Aging column a CASE Expression that returns NULL if StatusB is not null, or returns the DATEDIFF() between GETDATE() and StatusA if StatusB is null.
The same functionality is available in an SSRS expression if you prefer. You would use an IIF() instead of a CASE, and use TODAY instead of GETDATE() in the DATEDIFF().
I need to get from Access DataBase all items with dates during the current week. The first day of week is Monday. But i can't write any DatePart query. Last attempt was:
qModel->setQuery("SELECT * FROM TimeTable WHERE (DatePart(\"ww\",[PlayDate])=DatePart(\"ww\",Date()));");
Qt returns -3010 mistake:"[Microsoft][Driver ODBC Microsoft Access] Too few parameters. Expected 1."
Also i know that other similar queries with Year() or #SomeDate# is working.
So how can i get current week items?
Use single quotes instead of double quotes in the SQL statement.
qModel->setQuery("SELECT * FROM TimeTable WHERE DatePart('ww',[PlayDate])=DatePart('ww',Date());");
Assuming that change eliminated the error, next add the option to indicate which is the first day of your weeks.
qModel->setQuery("SELECT * FROM TimeTable WHERE DatePart('ww',[PlayDate],2)=DatePart('ww',Date(),2);");
I am working on a SSRS report that displays Date, Time and few other columns.
My SP returns just Date Column (which has time part in it) and a few other columns.
In the report I want to group by Date Part and show all details including the time (I used formatting option "T" to display only Time in Date column) in the details group.
For grouping on Date I used:
=FormatDateTime(Fields!TxDate.Value, DateFormat.ShortDate)
Which seems working. However if I try to sort on other columns it is not working. Any thoughts/suggestions on this?
It might be easier if you were to add an extra column into your dataset that was based on your original date+time column but containing just the date. Then you can use this to do a simple group on that column.
For example, if the dataset is based on a SQL query and your date+time column is called [Date], then add another column in the query as CONVERT(DATE, [Date]) AS DateOnly or something similar.