我在Microsoft Access中遇到左外连接查询问题。以下查询在SQL Server中正常工作,但它在M.S Access中不起作用。 使用C#..
Select Sales.ID as 'Sale ID',
Sales.Date,Customer.Name as 'Customer',
Sale_LINE_ITEMS.ITEMID as 'Item ID',
Items.description as 'Item Description',Items.Model as 'Model',
Items.brandquality as 'Brand Quality' ,
Sale_LINE_ITEMS.qty as 'Quantity',
Sale_LINE_ITEMS.UNITPRICE as 'Unit Price' ,
SALE_LINE_ITEMS.discount as 'Discount' ,
Sale_LINE_ITEMS.qty*Sale_LINE_ITEMS.UNITPRICE as 'Orignal Price',
Sale_LINE_ITEMS.qty*(Sale_LINE_ITEMS.UNITPRICE-Sale_LINE_ITEMS.discount) as 'Discounted Price',
Sale_LINE_ITEMS.TOTAL as 'Net Price'
from Sales, Customer, Items, Sale_LINE_ITEMS
left outer join Sales p
on p.ID=Sale_LINE_ITEMS.SID
where Sale_LINE_ITEMS.SID=Sales.ID
and Sales.Cid=Customer.id
and Sale_LINE_ITEMS.ITEMID=Items.id
and Sales.Date in (select date from Sales where date like '"+month+"/%' and date like '%/"+year+"')
order by Sales.Date,Sales.ID
答案 0 :(得分:0)
我认为这一行可能是你的问题
select date from Sales where date like '"+month+"/%' and date like '%/"+year+"'
msaccess中的通配符是* try
"select date from Sales where date like '" & month & "/*' and date like '*/" & year & "'
答案 1 :(得分:0)
我知道这已经很老了,但是对于任何人来说,这都是我的看法:您正在混合联接方法,方法是用逗号创建列表,然后在表“ Sales”上添加左外部联接。然后,在“销售”上设置“条件”。这会破坏左外部联接,而只是成为内部联接。 SQL Server通过允许您将条件放在LEFT OUTER JOIN子句的一部分(不使用令牌WHERE)中来提供最后一部分,并且SQL Server在维护联接时遵守此条件,但是MS Access不允许这样做。 >