简体   繁体   中英

Conversion failed when converting date and / or time from character string?

I was trying to create a procedure as follows :

CREATE PROC prc_invoice_add
AS
BEGIN
insert into INVOICE
(INV_NUMBER,CUS_CODE,INV_DATE)
VALUES (8006,1000,cast('30-APRL-08 00:00:00 AM ' as DATETIME2))
END

But whenever I execute this procedure this error message pops up :

"Conversion failed when converting date and/or time from character string".

try this,

CREATE PROC prc_invoice_add
AS
BEGIN
insert into INVOICE
(INV_NUMBER,CUS_CODE,INV_DATE)
VALUES (8006,1000,cast('30-APR-08 00:00:00 AM ' as DATETIME2))
END

your format of date is dd-MMM-yyyy, in this format APRIL is writtan as apr.

The problem is in Aprl

Pass it as April or Apr

try this

CREATE PROC prc_invoice_add
AS
BEGIN
insert into INVOICE
(INV_NUMBER,CUS_CODE,INV_DATE)
VALUES (8006,1000,cast('30-APRIL-08 00:00:00 AM ' as DATETIME2))
END

使用convert,专门用于施放日期时间。

CONVERT(DATETIME2,'30-APR-08 00:00:00 AM',113)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM