我正在嘗試在case語句中使TODATETIMEOFFSET工作。當我嘗試執行此操作時,SQL返回錯誤。如果它不在case語句中,可以正常工作。我究竟做錯了什麼?case case語句中的TODATETIMEOFFSET
SELECT AP.POR,
AP.POD Path,
TODATETIMEOFFSET(AP.StartTime, '-06:00') as StartTime,
MinimumPrice = (
CASE WHEN (CHARINDEX('','' + '''[email protected]+''' + '','', '','' + '''[email protected]+''' + '','') > 0)
THEN TODATETIMEOFFSET(AP.MinimumPrice, '-06:00')
ELSE ((
CASE WHEN (getdate() < C.ClearingTime and C.OpenPriceMask = 0)
THEN NULL
WHEN (getdate() > C.ClearingTime and C.ClearedPriceMask = 0)
THEN NULL
ELSE AP.MinimumPrice
END
))
END
),
AP.ClearingPrice,
AP.PriceUnits
FROM TES_Auction C
INNER JOIN TES_AuctionPrice AP ON AP.AuctionID = C.ID
Msg 206, Level 16, State 2, Line 1
Operand type clash: decimal is incompatible with datetime2
還我怎樣才能使 '爲' case語句的語法裏面工作?
正如一個側面說明,你有辦法更括號不必要。雖然它們有時對可讀性有幫助,但其他時間(例如'ELSE'子句中的雙括號),它們只會增加線路噪聲並傷害可讀性。將代碼分割成多行並仔細考慮縮進會比創建更多的括號來使複雜的SQL查詢更易於理解和維護。 – 2014-09-02 16:32:53
謝謝喬丹.. – 2014-09-02 18:59:09