MS Access / SQL Server 传递查询
我的查询确实运行,但没有返回结果:
SET NoCount ON
SELECT
Inventory.EffectiveDate,
Inventory.Quantity,
Inventory.SourceType,
Inventory.PickingLocation,
Inventory.SourceInventory,
Locations.LocationId,
Customers.CustomerName,
Products.ProductId,
LocationFrom.LocationId as lFrom,
LocationTo.LocationId as lTo
FROM (((((((dbo.Inventory AS Inventory
LEFT JOIN dbo.Products AS Products ON Products.Product = Inventory.Product )
LEFT JOIN dbo.Locations AS Locations ON Locations.Location = Inventory.Location )
LEFT JOIN dbo.Customers AS Customers ON Customers.ConsignmentLocation = Inventory.Location )
LEFT JOIN dbo.Inventory AS SourceLocation ON SourceLocation.Inventory = Inventory.SourceInventory)
LEFT JOIN dbo.Locations AS LocationFrom ON LocationFrom.Location = SourceLocation.Location )
LEFT JOIN dbo.Inventory AS TargetLocation ON TargetLocation.Inventory = Inventory.TargetInventory)
LEFT JOIN dbo.Locations AS LocationTo ON LocationTo.Location = TargetLocation.Location)
WHERE
(Inventory.SourceType = 'Q' OR Inventory.SourceType = 'G' OR Inventory.SourceType = 'P' OR Inventory.SourceType = 'A' OR Inventory.SourceType = 'B')
AND
((Inventory.EffectiveDate >= 2011-12-30 And Inventory.EffectiveDate <= 2011-12-31));
此查询从 Excel 运行良好。但我一直在寻找能够查看表格的工具,这就是我使用 Access 的原因 - 但这给我带来了更多问题......
My query does run, but returns no results:
SET NoCount ON
SELECT
Inventory.EffectiveDate,
Inventory.Quantity,
Inventory.SourceType,
Inventory.PickingLocation,
Inventory.SourceInventory,
Locations.LocationId,
Customers.CustomerName,
Products.ProductId,
LocationFrom.LocationId as lFrom,
LocationTo.LocationId as lTo
FROM (((((((dbo.Inventory AS Inventory
LEFT JOIN dbo.Products AS Products ON Products.Product = Inventory.Product )
LEFT JOIN dbo.Locations AS Locations ON Locations.Location = Inventory.Location )
LEFT JOIN dbo.Customers AS Customers ON Customers.ConsignmentLocation = Inventory.Location )
LEFT JOIN dbo.Inventory AS SourceLocation ON SourceLocation.Inventory = Inventory.SourceInventory)
LEFT JOIN dbo.Locations AS LocationFrom ON LocationFrom.Location = SourceLocation.Location )
LEFT JOIN dbo.Inventory AS TargetLocation ON TargetLocation.Inventory = Inventory.TargetInventory)
LEFT JOIN dbo.Locations AS LocationTo ON LocationTo.Location = TargetLocation.Location)
WHERE
(Inventory.SourceType = 'Q' OR Inventory.SourceType = 'G' OR Inventory.SourceType = 'P' OR Inventory.SourceType = 'A' OR Inventory.SourceType = 'B')
AND
((Inventory.EffectiveDate >= 2011-12-30 And Inventory.EffectiveDate <= 2011-12-31));
This query runs from Excel fine. But I was looking for the tool to be able to see tables, that's why I'm using Access - but it gives me more problems....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要用单引号将日期参数引起来。
您还应该考虑使用较短的别名以使代码更加简洁。我不确定使用
Products
这样的别名来表示dbo.Products
的目的...如果 Access 不强制,您还应该消除所有不必要的括号他们对你。You need to surround your date parameters with single quotes.
You should also consider using shorter aliases to make the code more concise. I'm not sure of the purpose of using an alias like
Products
to representdbo.Products
... you should also eliminate all the unnecessary parentheses if Access doesn't force them on you.