我是新來編寫SQL查詢時遇到與在SQL中的Smalldatetime
定義的所有我需要的是月開始至月底之間tblVehicleDepreciationLine.LineDate
日期時間列 tblVehicleDepreciationLine.LineDate
問題.. 我讀了20個不同的日期時間解決方案,但似乎無法破解我需要什麼代碼才能得到我的結果..SQL日期時間在一個月
任何幫助將不勝感激。
Select
tblVehicle.Rego,
tblVehicle.CompliancePlate,
tblVehicleType.Description,
tblVehicleEquipmentStatus.Description As Description1,
tblBranch.Name,
tblVehicleDepreciationLine.WDV,
tblVehicle.ID,
tblVehicleDepreciationLine.LineDate
From
tblVehicle
Inner Join tblVehicleType On tblVehicle.VehicleType_ID = tblVehicleType.ID
Inner Join tblVehicleEquipmentStatus On tblVehicle.VehicleEquipmentStatus_ID = tblVehicleEquipmentStatus.ID
Inner Join tblBranch On tblVehicle.ControllingBranch_ID = tblBranch.ID
Inner Join tblVehicleDepreciationLine On tblVehicleDepreciationLine.Vehicle_ID = tblVehicle.ID
Where
(tblVehicleDepreciationLine.LineDate >=
('(year(getdate()), month(getdate()), 1)') And
tblVehicle.VehicleEquipmentStatus_ID = 1)
Or
(tblVehicleDepreciationLine.LineDate <
('(year(getdate()), month(getdate())+1, 1)') And
tblVehicle.VehicleEquipmentStatus_ID = 2)
Order By
tblVehicle.ControllingBranch_ID
您使用的數據庫是多少? – jpw 2014-10-10 00:52:49