我对SQL Server并不熟悉,而且我有点卡在这里..
综合观点:
select *
from dbo.Elen_SalesData_View
where EffectiveDate>='2013-12-01' and EffectiveDate<='2013-12-31'
返回1319行。
Elen_SalesData_View
结构:
SELECT
ItemCode, ItemDescription, ItemValue, Quantity,
CustomerId, CustomerName, SalesInvoiceId, EffectiveDate,
CountryId
FROM
dbo.Elen_SalesData_Historical
UNION ALL
SELECT
ItemCode, ItemDescription, ItemValue, Quantity,
CustomerId, CustomerName, SalesInvoiceId, EffectiveDate,
CountryId
FROM
dbo.Elen_SalesData_Current
在这个实例中, Elen_SalesData_Current
将不返回任何内容。所以我们忽略它..
Elen_SalesData_Historical
包括:
SELECT
CONVERT(varchar(30), ItemCode) AS ItemCode, Product,
CONVERT(varchar(60), ItemDescription) AS ItemDescription,
ItemValue, Quantity, ItemType,
CustomerId, CustomerName,
SalesInvoiceId, EffectiveDate, CountryId
FROM
db1.dbo.Elen_WinmanSalesArch
返回1319行。
Elen_WinmanSalesArch
运行的位置:
select *
from Elen_WinmanSalesArch
where EffectiveDate>='2013-12-01' and EffectiveDate<='2013-12-31'
返回3489行 - 这是正确的!
为什么呢?以及如何解决它?
也许值得一提的是Elen_WinmanSalesArch
正在查询一个数据库,而Elen_SalesData_Historical
则是从另一个数据库运行
刚开始测试:
select * from dbo.Elen_SalesData_Historical
where EffectiveDate>='2013-12-01' and EffectiveDate<='2013-12-31'
返回1319行。 Elen_SalesData_Historical
是一个视图,其内容如上所述。但是当我跑步时:
SELECT CONVERT(varchar(30), ItemCode) AS ItemCode, Product,
CONVERT(varchar(60), ItemDescription) AS ItemDescription,
ItemValue, Quantity, ItemType, CustomerId,
CustomerName, SalesInvoiceId, EffectiveDate, CountryId
FROM db1.dbo.Elen_WinmanSalesArch
where EffectiveDate>='2013-12-01' and EffectiveDate<='2013-12-31'
它返回3489行!我真的很困惑......