我這種情況在存儲過程:TSQL - 在存儲過程中的錯誤,由於轉換失敗
SET @DATE_RELEASE_START = '2015-01-01';
SET @DATE_RELEASE_END = '2015-05-31'
SELECT @statement = ' SELECT *
FROM (SELECT AFCDENTE, M.ID_MODIFICATION_CODE, COUNT(*) AS Conteggio--, CAST((COUNT(*) * 100/ 15032) AS decimal(10,7)) AS Percentage
FROM CIC_LOG_MODIFICHE AS L INNER JOIN ADM_MODIFICATION_CODE AS M ON L.CD_MODIFICATION_CODE = M.CD_MODIFICATION_CODE
INNER JOIN CIC_PRODUZIONE AS P ON P.CD_CIC_PRODUZIONE = L.CD_CIC_PRODUZIONE
WHERE AFDTMODI BETWEEN '[email protected]_RELEASE_START+' AND '[email protected]_RELEASE_END+' AND P.CD_PLANT = '[email protected]_PLANT+' AND AFCDENTE IS NOT NULL
GROUP BY AFCDENTE, M.ID_MODIFICATION_CODE) as tbl
PIVOT (SUM(tbl.Conteggio) for tbl.ID_MODIFICATION_CODE in (' + @columns + ')) as pvt'
我得到這個錯誤:
Conversion failed when converting date and/or time from character string.
我試圖鑄造的日期,但沒有改變。我犯了同樣的錯誤。
我該怎麼辦?
哎呀!如果類型是'datetime'或者傳遞一個時間組件,則需要使用'YYYYMMDD'。 'YYYY-MM-DD'適用於'date'類型 –
我使用'DATETIME2'並根據文檔支持'YYYY-MM-DD'。 https://msdn.microsoft.com/en-us/library/bb677335.aspx糾正我,如果我錯了。 –
好工作。它的作品 – Galma88