0
我正在嘗試使用變量爲我的開始日期和結束日期運行查詢。在查詢中使用變量作爲日期範圍
Declare @startshiptransdate as datetime
Declare @endshiptransdate as datetime
SET @StartShipTransDate = ISNULL(@StartShipTransDate, '08/30/2015')
SET @EndShipTransDate = ISNULL(@EndShipTransDate, '09/05/2015')
(convert(date,co_ship.ship_date,101) >= @StartShipTransDate
AND convert(date,co_ship.ship_date, 101) <= @EndShipTransDate)
當我運行這個時,我得到了大約200條記錄,我應該有什麼。
但是,如果我是這樣運行的:
(convert(date, co_ship.ship_date, 101) >= '08/30/2015'
AND convert(date, co_ship.ship_date, 101) <= '09/05/2015')
我得到正確的記錄數。我相信這很簡單。
能否請您粘貼整個查詢?您將零件排除在外,這使得難以排除故障。 – rwking
當你將變量聲明爲日期而不是日期時,你是否得到相同的效果? –
@EricHauenstein是的 – DragonRider