尝试从 3 个不同的表中检索列,TurnTime 是来自第 4 个表的 DATEDIFF
CustomerName, OrderTypeName, LoanNumber, TurnTime1, TurnTime2,TurnTime3, TurnTime4
表:
tblCustomer, tblOrderType, tblOrder, tblOrderActivity, tblActivity
放置 DATEDIFF 时遇到语法错误。我认为我做错了,并试图在时代有所不同。
下表在 tblOrderActivity 中用于 DATEDIFF
tblActivity ActivityID ActivityName
1 Received
2 Keyed
3 Printed
4 Delivered
我想从 1-2、2-3、3-4、1-4 中找到 DATEDIFF。ActivityID
并且ActivityDate
在tbl.OrderActivity
我试图将一个(Select DATEDIFF
与INNERJOIN
我希望从中检索日期的表放在一起,但是,它也导致了语法错误。这是我当前的代码:
SELECT
dbo.tblCustomer.CustomerName, dbo.tblOrderType.OrderTypeName, dbo.tblOrder.LoanNumber,
dbo.tblOrderActivity.ActivityDate,
DATEDIFF(MINUTE, ActivityID=1, ActivityID=2) AS TurnTime1,
DATEDIFF(MINUTE, ActivityID=2, ActivityID=3) AS TurnTime2,
DATEDIFF(MINUTE, ActivityID=3, ActivityID=4) AS TurnTime3,
DATEDIFF(MINUTE, ActivityID=1, ActivityID=4) AS TurnTime4
FROM
dbo.tblOrder
INNER JOIN
dbo.tblCustomer ON dbo.tblOrder.CustomerID = dbo.tblCustomer.CustomerID
INNER JOIN
dbo.tblOrderActivity ON dbo.tblOrder.OrderID = dbo.tblOrderActivity.OrderID AND
dbo.tblOrder.OrderID = dbo.tblOrderActivity.OrderID
INNER JOIN
dbo.tblActivity ON dbo.tblOrderActivity.ActivityID = dbo.tblActivity.ActivityID
INNER JOIN
dbo.tblOrderType ON dbo.tblOrder.OrderTypeID = dbo.tblOrderType.OrderTypeID
ORDER BY dbo.tblCustomer.CustomerName, dbo.tblOrderType.OrderTypeName, dbo.tblOrder.LoanNumber