我确信已经以不同的方式提出了这个问题,但由于某种原因,我束手无策。我正在执行一个非常直接的 SELECT INTO FROM 语句,其中包括要添加的日期的 WHERE,但我无法创建临时表 - 我不断收到上述错误。尝试了各种 CONVERT/CAST 等,但没有运气。日期以这种格式存储在数据库中:2017-01-02 00:00:00.000 但我在数据库的其他区域使用“01/01/2017”进行查询没有问题。
SQL 代码:
SELECT AO.SALES_ORDER_NUMBER AS 'SALES_ORDER_NUMBER',
AO.SALES_ORDER_ITEM_NUMBER AS 'SALES_ORDER_ITEM_NUMBER',
II.BILLING_DOCUMENT_NUMBER AS 'BILLING_DOCUMENT_NUMBER',
CASE
WHEN IH.SOLD_TO = '0000006070'
THEN '66400'
WHEN IH.SOLD_TO = '0000006075'
THEN '66315'
ELSE AO.BILL_TO
END AS 'BILL_TO',
AO.MATERIAL AS 'MATERIAL',
AO.SIZE_INDEX AS 'SIZE_INDEX',
AO.REQUESTED_DELIVERY_DATE AS 'REQUESTED_DELIVERY_DATE'
INTO ##Temp_Invoiced
FROM VW_AR_ORDER_ORIGINAL AO
JOIN VW_INVOICES_ITEM II ON AO.SALES_ORDER_ITEM_NUMBER = II.SALES_ORDER_ITEM_NUMBER AND AO.SALES_ORDER_NUMBER = II.SALES_ORDER_NUMBER
JOIN VW_INVOICES_HEADER IH ON II.BILLING_DOCUMENT_NUMBER = IH.BILLING_DATE
WHERE AO.STOCK_CATEGORY LIKE '%1002%'
AND AO.REQUESTED_DELIVERY_DATE >= '01/01/2017';