以下查询用于报告,报告仍然在访问时显示实时数据,但在Management Studio中运行查询时,尽管消息“查询已成功完成”,但仍未收到任何结果&#39; < / p>
我必须声明@Date参数,我认为我已经在查询的顶部正确完成了。
DECLARE @Date datetime;
BEGIN
SET @Date = 27/07/2017;
END
SELECT CAST(CASE WHEN (SOTD_STWH_CODE = 'HPP SHEF') THEN DATE - (CASE
DATEPART(dw, DATE) WHEN 2 THEN 3 ELSE 1 END) ELSE DATE END AS date) AS
ShipDate,
DeFactoUser.F_SO_Transaction.SOTR_CUST_CODE,
DeFactoUser.F_SO_Transaction_Details.SOTD_HEAD_NO,
DeFactoUser.F_SO_Transaction.SOTR_DLSC_CODE,
DeFactoUser.F_SO_Transaction_Details.SOTD_STWH_CODE,
DeFactoUser.F_SO_Transaction_Details.SOTD_STRC_CODE,
DeFactoUser.F_SO_Transaction_Details.SOTD_QTY_UNITS_ORDERED,
DeFactoUser.F_SO_Transaction_Details.SOTD_QTY_UNITS_OUTSTANDING,
DeFactoUser.F_SO_Transaction_Details.SOTD_QTY_UNITS_PICKED,
DeFactoUser.F_BM_Transactions_Details.BMTD_BMTR_SYS_NO,
DeFactoUser.F_BM_Transactions_Details.BMTD_QTY_OUTSTANDING,
ISNULL(CAST(BaseOn.baseon AS varchar), '') AS BaseOn,
CASE BaseOn.baseonstat WHEN '99' THEN 'Complete' WHEN
'98' THEN 'Outstanding' WHEN '1' THEN 'open' ELSE '' END AS BaseOnStatus,
DeFactoUser.F_SL_Customers.CUST_NAME
FROM DeFactoUser.F_SL_Customers INNER JOIN
DeFactoUser.F_SO_Transaction_Details WITH (NOLOCK) INNER
JOIN
DeFactoUser.F_ST_Products WITH (NOLOCK) ON
DeFactoUser.F_SO_Transaction_Details.SOTD_STRC_CODE =
DeFactoUser.F_ST_Products.STRC_CODE INNER JOIN
DeFactoUser.F_SO_Transaction WITH (NOLOCK) ON
DeFactoUser.F_SO_Transaction_Details.SOTD_HEAD_NO =
DeFactoUser.F_SO_Transaction.SOTR_SYS_NO INNER JOIN
tbl_DFBI_Date ON
DeFactoUser.F_SO_Transaction.SOTR_PROMISED_DATE = tbl_DFBI_Date.Date ON
DeFactoUser.F_SL_Customers.CUST_CODE =
DeFactoUser.F_SO_Transaction_Details.SOTD_CUST_CODE LEFT OUTER JOIN
DeFactoUser.F_BM_Transactions INNER JOIN
DeFactoUser.F_BM_Transactions_Details ON
DeFactoUser.F_BM_Transactions.BMTR_SYS_NO =
DeFactoUser.F_BM_Transactions_Details.BMTD_BMTR_SYS_NO ON
DeFactoUser.F_SO_Transaction_Details.SOTD_SYS_NO =
DeFactoUser.F_BM_Transactions_Details.BMTD_ORDER_LINK_NUMBER LEFT OUTER JOIN
(SELECT RIGHT(SOTR_BASED_ON_REF, 7) AS link,
SOTR_STATUS AS baseonstat, SOTR_SYS_NO AS baseon
FROM DeFactoUser.F_SO_Transaction AS
F_SO_Transaction_1
WHERE (SOTR_CUST_CODE = 'h075') AND
(SOTR_BASED_ON_REF > '0')) AS BaseOn ON
CAST(DeFactoUser.F_SO_Transaction_Details.SOTD_HEAD_NO AS varchar) =
BaseOn.link
WHERE (DeFactoUser.F_ST_Products.STRC_NI_CODE = 'panelcut') AND
(DeFactoUser.F_ST_Products.STRC_ANAL1 = '1033') AND
(DeFactoUser.F_SO_Transaction_Details.SOTD_SOTR_TYPE = 10) AND
(DeFactoUser.F_SO_Transaction.SOTR_CUST_CODE <> 'h075')
AND (DeFactoUser.F_SO_Transaction.SOTR_STATUS < '99') AND (CASE WHEN
(SOTD_STWH_CODE = 'HPP SHEF')
THEN DATE - (CASE DATEPART(dw, DATE) WHEN 2 THEN 3 ELSE 1
END) ELSE DATE END <= @Date)
关于如何查看结果的任何建议?
答案 0 :(得分:1)
您需要以下内容来初始化日期:
{{1}}
你现在拥有的是,27除以7除以2017.这些是整数,因此结果是0.这个数字然后被转换为日期时间,这不会产生你想要的日期。
您最好坚持使用日期或日期/时间值的ISO 8601格式。您可以在DATETIME文档中了解更多相关信息。