Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create tables with correct data fomat in sql?

In my sql query, I am getting the output as below.

insert into terminationdata (Name,Date,Calls,Answered_Calls,Total_Minutes) values('XXX',2021-12-17,'480298','120758.0','391238.6333') ON DUPLICATE KEY UPDATE name=VALUES(name),Date=VALUES(Date),calls=VALUES(calls),Answered_Calls=VALUES(Answered_Calls),Total_Minutes=VALUES(Total_Minutes)

I have created a new table as below to save all the data.

create table terminationdata(
   Name VARCHAR(20) NULL ,
   Date DATETIME NULL ,
   Calls INT NULL DEFAULT '0',
   Answered_Calls INT NULL DEFAULT '0',
   Total_Minutes DECIMAL(8,2) NULL
 
  
);

The query is working fine but the date is not correctly fetched in table. In table the date is shown as 0000-00-00 00:00:00. How should I get the correct date(ex-2021/12/19)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried Date DATE NULL instead of Date DATETIME NULL .But the same error is there.

>Solution :

encapsulate your datetime value with single quotes. It will be automatically cast to datetime (if your string value is a valid datetime).

insert into terminationdata (Name,Date,Calls,Answered_Calls,Total_Minutes) values('XXX','2021-12-17','480298','120758.0','391238.6333') ON DUPLICATE KEY UPDATE name=VALUES(name),Date=VALUES(Date),calls=VALUES(calls),Answered_Calls=VALUES(Answered_Calls),Total_Minutes=VALUES(Total_Minutes)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading