我执行select语句
select
Orders.Oid as 'Order ID',
Eid as 'Employee ID',
Barcode,
PacksQty as 'Packs Quantity',
UnitQty as 'Units Quantity',
Date as 'Order Date',
Price as 'Total Price'
from OrderDetails
inner join Orders
on OrderDetails.Oid = Orders.Oid
where OrderDetails.Date ='05/07/2013'
它不会检索数据,也不会给我任何错误。顺便说一下,表格行中的数据在Date列中具有指定的日期。
答案 0 :(得分:0)
因为查询没有丢失,这意味着查询正在成功执行,这留下了以下可能性:
SELECT COUNT(*) AS DateCount FROM OrderDetails WHERE Date = '05/07/2013'
如果返回0,那么您没有该日期的OrderDetails,如果它返回1或更多,请执行以下操作
SELECT COUNT(*) AS OrdersWithDateCount
FROM Orders
JOIN OrderDetails
ON Orders.Oid = OrderDetails.Oid
WHERE OrderDetails.Date = '05/07/2013'
如果您在上面的示例中返回零,但在下面的示例中不返回零
SELECT COUNT(*) AS OrderDetailsWithDateCount
FROM OrderDetails
WHERE Date = '05/07/2013'
您有详细记录但没有订单记录或孤立记录。确保您有正确的日期,请执行以下操作
SELECT DISTINCT Date
FROM OrderDetails
WHERE Date BETWEEN GETDATE()-90 AND GETDATE()
如果您看到日期匹配,可能是因为您的数据类型是日期时间,请尝试使用
DECLARE @TargetDate DATE = '05/07/2013'
SELECT COUNT(*) FROM OrderDetails
WHERE OrderDetails.Date
BETWEEN DATEADD(day,-1,@TargetDate)
AND DATEADD(day,1,@TargetDate)
如果这确实返回了0以外的其他内容,那么您需要使用此方法来获得正确的结果。如果它确实返回0,那么您肯定没有日期为'05/07/2013'
答案 1 :(得分:0)
试试这个
select Orders.Oid as 'Order ID',Eid as 'Employee ID',Barcode,PacksQty as 'Packs Quantity',
UnitQty as 'Units Quantity',Date as 'Order Date',Price as 'Total Price' from
OrderDetails join Orders
on OrderDetails.Oid = Orders.Oid
Where OrderDetails.Date ='2031-07-05'
答案 2 :(得分:0)
试试这个..使用如图所示的日期格式 其中OrderDetails.Date ='2031 7月 05'
OrderDetails.Date的类型是什么? 是日期时间还是日期..? 如果其日期时间更改条件为
WHERE CONVERT(CHAR(12),OrderDetails.Date,13)='2013年7月5日'