fletchsod
Programmer
- Dec 16, 2002
- 181
I'm trying to understand why does the sql query run faster with the view instead of without it.. The one with the view took 14 seconds while the one without the view took 4 hours.
The source code for the view "vwAvgSale" is
This one I used without the view is
I welcome some help and explaination on why there is disparity between these two (with and without view)... I don't really know what the problem is... I looked at the database index and it looked fine.
Thanks...
Code:
SELECT TOP 10 'F', tblSold.Year, tblSold.MakeID, tblSold.ModelID
FROM vwAvgSale
WHERE tblSold.SoldDate >= @SearchDate
AND tblSold.SaleType = 'R'
AND tblvZipCodes.City = @City
AND tblvZipCodes.State = @State
The source code for the view "vwAvgSale" is
Code:
SELECT tblSold.Year, tblSold.MakeID, tblSold.ModelID
FROM dbo.tblSold INNER JOIN
dbo.tblvZipCodes ON dbo.tblSold.ZipCode = dbo.tblvZipCodes.ZIPCode AND dbo.tblSold.City = dbo.tblvZipCodes.City INNER JOIN
dbo.tblvRegions ON dbo.tblvZipCodes.Region = dbo.tblvRegions.RegionID
ORDER BY dbo.tblSold.SoldID DESC
This one I used without the view is
Code:
SELECT TOP 10 'F', tblSold.Year, tblSold.MakeID, tblSold.ModelID
[B]
FROM dbo.tblSold INNER JOIN
dbo.tblvZipCodes ON dbo.tblSold.ZipCode = dbo.tblvZipCodes.ZIPCode AND dbo.tblSold.City = dbo.tblvZipCodes.City INNER JOIN
dbo.tblvRegions ON dbo.tblvZipCodes.Region = dbo.tblvRegions.RegionID
[/B]
WHERE tblSold.SoldDate >= @SearchDate
AND tblSold.SaleType = 'R'
AND tblvZipCodes.City = @City
AND tblvZipCodes.State = @State
I welcome some help and explaination on why there is disparity between these two (with and without view)... I don't really know what the problem is... I looked at the database index and it looked fine.
Thanks...