February 27, 2019 at 10:54 pm
I have two tables named order and order_line...orderline is related to order by orderid.Calculates the sum of durations from orderline table and add it with the time column in order table as end time and check whether the end time exeeds the current time,if exeeds return the order rows
February 27, 2019 at 11:39 pm
amalbaby - Wednesday, February 27, 2019 10:54 PMI have two tables named order and order_line...orderline is related to order by orderid.Calculates the sum of durations from orderline table and add it with the time column in order table as end time and check whether the end time exeeds the current time,if exeeds return the order rows
Kindly provide test data with create and insert statement. Also what you tried so far?
Saravanan
February 27, 2019 at 11:55 pm
table datas
---------------
Order table
Order line
I want to find the sum of duration column and add it with appoint_time for each order
February 28, 2019 at 1:11 am
amalbaby - Wednesday, February 27, 2019 11:55 PMtable datas
---------------Order table
Order line
I want to find the sum of duration column and add it with appoint_time for each order
A picture really does not help you need to post DDL and DML, and your expected results.
...
February 28, 2019 at 3:01 pm
I've never actually used the Time datatype before, which is what it looks like you are using for OrderLine.duration. Based on my testing, it seems like the following should work for what you need. Note it is limited to minutes, it doesn't process fractions of a minute.
SELECT
O.id AS OrderID,
O.appointment_date AS ApptDate,
SUM(DATEDIFF(MINUTE, '0:00:00', OL.duration)) AS SumDuration,
CAST(SUM(DATEDIFF(MINUTE, '0:00:00', OL.duration)) AS DATETIME) + CAST(O.appointment_date AS DATETIME) AS FinalDateTime,
GETDATE() AS CurrentDateTime
FROM [Order] AS O
INNER JOIN [OrderLine] AS OL ON
O.id = OL.order_id
GROUP BY
O.id,
O.appointment_date
HAVING
CAST(SUM(DATEDIFF(MINUTE, '0:00:00', OL.duration)) AS DATETIME) + CAST(O.appointment_date AS DATETIME) > GETDATE()
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply