链接服务器上的 getdate() 给我一个错误
getdate() on linked server gives me an error
我有以下 TSQl 语句,它使用链接服务器从 sage 检索销售订单,但我不明白为什么这一行 JrnlHdr.TransactionDate = cast(GETDATE())
给我任何错误。我可以在没有 JrnlHdr.TransactionDate = cast(GETDATE())
的情况下检索所有记录,但我只想查看今天创建的销售订单。
这里是select声明
SELECT * FROM OPENQUERY([SAGE],'SELECT DISTINCT Customers.CustomerID, Customers.Customer_Bill_Name, Customers.WhichShipVia,
LineItem.ItemID as I, JrnlHdr.INV_POSOOrderNumber, JrnlHdr.CustomerInvoiceNo,
JrnlHdr.Comment2, JrnlHdr.ShipByDate, JrnlHdr.GoodThruDate, JrnlHdr.CustomerSONo, JrnlHdr.Reference, JrnlHdr.TransactionDate,
JrnlRow.DistNumber, CAST (JrnlRow.Quantity AS NUMERIC (20,4)), LineItem.ItemID, LineItem.SalesDescription, LineItem.PartNumber, LineItem.Category, LineItem.ItemClass, LineItem.ItemDescription
FROM Customers
INNER JOIN JrnlHdr
ON Customers.CustomerRecordNumber = JrnlHdr.CustVendId
LEFT OUTER JOIN Address
ON Customers.CustomerRecordNumber = Address.CustomerRecordNumber
INNER JOIN JrnlRow
ON JrnlHdr.PostOrder = JrnlRow.PostOrder
INNER JOIN LineItem
ON JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber
WHERE JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate = cast(GETDATE()) AND JrnlHdr.PostOrder = JrnlRow.PostOrder AND JrnlHdr.CustVendId = Customers.CustomerRecordNumber AND JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber AND JrnlHdr.POSOisClosed = 0')
这是我收到的错误消息
OLE DB provider "PervasiveOLEDB.11.0" for linked server "SAGE"
returned message "One or more errors occurred during processing of
command.". OLE DB provider "PervasiveOLEDB.11.0" for linked server
"SAGE" returned message "[Pervasive][ODBC Engine Interface]Syntax
Error: N JrnlHdr.PostOrder = JrnlRow.PostOrder INNER JOIN LineItem ON
JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber WHERE
JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate =
cast(GETDATE()<< ??? ". Msg 7321, Level 16, State 2, Line 1 An error
occurred while preparing the query "SELECT DISTINCT
Customers.CustomerID, Customers.Customer_Bill_Name,
Customers.WhichShipVia, LineItem.ItemID as I,
JrnlHdr.INV_POSOOrderNumber, JrnlHdr.CustomerInvoiceNo,
JrnlHdr.Comment2, JrnlHdr.ShipByDate, JrnlHdr.GoodThruDate,
JrnlHdr.CustomerSONo, JrnlHdr.Reference, JrnlHdr.TransactionDate,
JrnlRow.DistNumber, CAST (JrnlRow.Quantity AS NUMERIC (20,4)),
LineItem.ItemID, LineItem.SalesDescription, LineItem.PartNumber,
LineItem.Category, LineItem.ItemClass, LineItem.ItemDescription FROM
Customers INNER JOIN JrnlHdr ON Customers.CustomerRecordNumber =
JrnlHdr.CustVendId LEFT OUTER JOIN Address ON
Customers.CustomerRecordNumber = Address.CustomerRecordNumber INNER
JOIN JrnlRow ON JrnlHdr.PostOrder = JrnlRow.PostOrder INNER JOIN
LineItem ON JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber
WHERE JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate =
cast(GETDATE()) AND JrnlHdr.PostOrder = JrnlRow.PostOrder AND
JrnlHdr.CustVendId = Customers.CustomerRecordNumber AND
JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber AND
JrnlHdr.POSOisClosed = 0" for execution against OLE DB provider
"PervasiveOLEDB.11.0" for linked server "SAGE".
由于您显然是在远程 Pervasive 数据库上执行查询,因此您需要使用该 DBMS 的语法,即 CURDATE()
而不是 GETDATE()
。
你能试试这个吗?
SELECT * FROM OPENQUERY([SAGE],'SELECT DISTINCT Customers.CustomerID, Customers.Customer_Bill_Name, Customers.WhichShipVia,
LineItem.ItemID as I, JrnlHdr.INV_POSOOrderNumber, JrnlHdr.CustomerInvoiceNo,
JrnlHdr.Comment2, JrnlHdr.ShipByDate, JrnlHdr.GoodThruDate, JrnlHdr.CustomerSONo, JrnlHdr.Reference, JrnlHdr.TransactionDate,
JrnlRow.DistNumber, CAST (JrnlRow.Quantity AS NUMERIC (20,4)), LineItem.ItemID, LineItem.SalesDescription, LineItem.PartNumber, LineItem.Category, LineItem.ItemClass, LineItem.ItemDescription
FROM Customers
INNER JOIN JrnlHdr
ON Customers.CustomerRecordNumber = JrnlHdr.CustVendId
LEFT OUTER JOIN Address
ON Customers.CustomerRecordNumber = Address.CustomerRecordNumber
INNER JOIN JrnlRow
ON JrnlHdr.PostOrder = JrnlRow.PostOrder
INNER JOIN LineItem
ON JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber
WHERE JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate = cast(CURDATE()) AND JrnlHdr.PostOrder = JrnlRow.PostOrder AND JrnlHdr.CustVendId = Customers.CustomerRecordNumber AND JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber AND JrnlHdr.POSOisClosed = 0')
我有以下 TSQl 语句,它使用链接服务器从 sage 检索销售订单,但我不明白为什么这一行 JrnlHdr.TransactionDate = cast(GETDATE())
给我任何错误。我可以在没有 JrnlHdr.TransactionDate = cast(GETDATE())
的情况下检索所有记录,但我只想查看今天创建的销售订单。
这里是select声明
SELECT * FROM OPENQUERY([SAGE],'SELECT DISTINCT Customers.CustomerID, Customers.Customer_Bill_Name, Customers.WhichShipVia,
LineItem.ItemID as I, JrnlHdr.INV_POSOOrderNumber, JrnlHdr.CustomerInvoiceNo,
JrnlHdr.Comment2, JrnlHdr.ShipByDate, JrnlHdr.GoodThruDate, JrnlHdr.CustomerSONo, JrnlHdr.Reference, JrnlHdr.TransactionDate,
JrnlRow.DistNumber, CAST (JrnlRow.Quantity AS NUMERIC (20,4)), LineItem.ItemID, LineItem.SalesDescription, LineItem.PartNumber, LineItem.Category, LineItem.ItemClass, LineItem.ItemDescription
FROM Customers
INNER JOIN JrnlHdr
ON Customers.CustomerRecordNumber = JrnlHdr.CustVendId
LEFT OUTER JOIN Address
ON Customers.CustomerRecordNumber = Address.CustomerRecordNumber
INNER JOIN JrnlRow
ON JrnlHdr.PostOrder = JrnlRow.PostOrder
INNER JOIN LineItem
ON JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber
WHERE JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate = cast(GETDATE()) AND JrnlHdr.PostOrder = JrnlRow.PostOrder AND JrnlHdr.CustVendId = Customers.CustomerRecordNumber AND JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber AND JrnlHdr.POSOisClosed = 0')
这是我收到的错误消息
OLE DB provider "PervasiveOLEDB.11.0" for linked server "SAGE" returned message "One or more errors occurred during processing of command.". OLE DB provider "PervasiveOLEDB.11.0" for linked server "SAGE" returned message "[Pervasive][ODBC Engine Interface]Syntax Error: N JrnlHdr.PostOrder = JrnlRow.PostOrder INNER JOIN LineItem ON JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber WHERE JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate = cast(GETDATE()<< ??? ". Msg 7321, Level 16, State 2, Line 1 An error occurred while preparing the query "SELECT DISTINCT Customers.CustomerID, Customers.Customer_Bill_Name, Customers.WhichShipVia, LineItem.ItemID as I, JrnlHdr.INV_POSOOrderNumber, JrnlHdr.CustomerInvoiceNo, JrnlHdr.Comment2, JrnlHdr.ShipByDate, JrnlHdr.GoodThruDate, JrnlHdr.CustomerSONo, JrnlHdr.Reference, JrnlHdr.TransactionDate, JrnlRow.DistNumber, CAST (JrnlRow.Quantity AS NUMERIC (20,4)), LineItem.ItemID, LineItem.SalesDescription, LineItem.PartNumber, LineItem.Category, LineItem.ItemClass, LineItem.ItemDescription FROM Customers INNER JOIN JrnlHdr ON Customers.CustomerRecordNumber = JrnlHdr.CustVendId LEFT OUTER JOIN Address ON Customers.CustomerRecordNumber = Address.CustomerRecordNumber INNER JOIN JrnlRow ON JrnlHdr.PostOrder = JrnlRow.PostOrder INNER JOIN LineItem ON JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber WHERE JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate = cast(GETDATE()) AND JrnlHdr.PostOrder = JrnlRow.PostOrder AND JrnlHdr.CustVendId = Customers.CustomerRecordNumber AND JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber AND JrnlHdr.POSOisClosed = 0" for execution against OLE DB provider "PervasiveOLEDB.11.0" for linked server "SAGE".
由于您显然是在远程 Pervasive 数据库上执行查询,因此您需要使用该 DBMS 的语法,即 CURDATE()
而不是 GETDATE()
。
你能试试这个吗?
SELECT * FROM OPENQUERY([SAGE],'SELECT DISTINCT Customers.CustomerID, Customers.Customer_Bill_Name, Customers.WhichShipVia,
LineItem.ItemID as I, JrnlHdr.INV_POSOOrderNumber, JrnlHdr.CustomerInvoiceNo,
JrnlHdr.Comment2, JrnlHdr.ShipByDate, JrnlHdr.GoodThruDate, JrnlHdr.CustomerSONo, JrnlHdr.Reference, JrnlHdr.TransactionDate,
JrnlRow.DistNumber, CAST (JrnlRow.Quantity AS NUMERIC (20,4)), LineItem.ItemID, LineItem.SalesDescription, LineItem.PartNumber, LineItem.Category, LineItem.ItemClass, LineItem.ItemDescription
FROM Customers
INNER JOIN JrnlHdr
ON Customers.CustomerRecordNumber = JrnlHdr.CustVendId
LEFT OUTER JOIN Address
ON Customers.CustomerRecordNumber = Address.CustomerRecordNumber
INNER JOIN JrnlRow
ON JrnlHdr.PostOrder = JrnlRow.PostOrder
INNER JOIN LineItem
ON JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber
WHERE JrnlHdr.JrnlKey_Journal = 11 AND JrnlHdr.TransactionDate = cast(CURDATE()) AND JrnlHdr.PostOrder = JrnlRow.PostOrder AND JrnlHdr.CustVendId = Customers.CustomerRecordNumber AND JrnlRow.ItemRecordNumber = LineItem.ItemRecordNumber AND JrnlHdr.POSOisClosed = 0')