0
With Vehicles As (
Select Row_Number() Over (Order By Model.[Year] Desc, Vehicle.Msrp Asc, Vehicle.Id) As RowNumber
, Make.[Name] As Style_Model_Make_Name
, Model.[Name] As Style_Model_Name
, Model.[Year] As Style_Model_Year
, Style.Trim As Style_Trim
, Style.[Name] As Style_Name
, Style.BodyType As Style_BodyType
, Vehicle.CompanyId As Company_Id
, Vehicle.Id
, Vehicle.StyleId As Style_Id
, Vehicle.[Status]
, Vehicle.Vin
, Vehicle.StockNumber
, Vehicle.ModelCode
, Vehicle.Mileage
, Vehicle.InteriorColor
, Vehicle.InteriorColorCode
, Vehicle.ExteriorColor
, Vehicle.ExteriorColorCode
, Vehicle.Certification
, Vehicle.Selling
, Vehicle.Internet
, Vehicle.Special
, Vehicle.Comment
, Vehicle.IsNew
, Vehicle.IsCertified
, Vehicle.StockDate
From dbo.Vehicle (NoLock)
Join dbo.Style (NoLock) On Style.Id = Vehicle.StyleId
Left Join dbo.Engine ON dbo.Style.Id = dbo.Engine.StyleId
Inner Join dbo.Model on dbo.Model.Id = dbo.Style.ModelId
Inner Join dbo.Make ON dbo.Model.MakeId = dbo.Make.Id ON dbo.Style.ModelId = dbo.Model.Id
Where Vehicle.CompanyId in (9)
And Vehicle._IsActive = 1
And DateDiff(day, Vehicle.StockDate, GetDate()) >= @DaysInStock
And Vehicle.Msrp Between @PriceMin And @PriceMax
And Vehicle.Mileage Between @MileageMin And @MileageMax And Convert(int, Model.[Year]) Between @YearMin And @YearMax And Vehicle.IsNew = 1)
Select Style_Model_Make_Name
, Style_Model_Name
, Style_Model_Year
, Style_Id
, Style_Trim
, Style_Name
, Style_BodyType
, Company_Id
, Vehicle.Id
, Vehicle.Vin
, Vehicle.Mileage
, Vehicle.StockNumber
, Vehicle.ModelCode
, Vehicle.InteriorColor
, Vehicle.InteriorColorCode
, Vehicle.ExteriorColor
, Vehicle.ExteriorColorCode
, Vehicle.Certification
, Case When Vehicle.Msrp < @CallPrice Then 0 Else Vehicle.Msrp End As Msrp
, Case When Vehicle.Selling < @CallPrice Then 0 Else Vehicle.Selling End As Selling
, Vehicle.Internet
, Vehicle.Special
, Vehicle.Comment
, Vehicle.IsNew
, Vehicle.IsCertified
, Vehicle.StockDate
From Vehicles
Where RowNumber Between @StartRowIndex And (@StartRowIndex + @MaximumRows) - 1
我是新來的sql服務器,並試圖弄清楚事情。 我正在嘗試創建一個CTE,以便更輕鬆地選擇不同的列。我認爲我的FROM聲明有問題,但我不確定究竟是什麼錯誤。第二個SELECT語句中的所有列都有紅色的sqiggles,它們返回並且「多部分標識符」錯誤「無法綁定」錯誤。有任何想法如何解決這個問題?多部分標識符「」不能綁定sql服務器2008
感謝您的幫助! – user1169520