Home > Software engineering >  How to trim Column Value SQL
How to trim Column Value SQL

Time:12-14

Table1:

Intime
17:44:58.2555247

How to Trim '2555247'from Intime value Looking for output "17:44:58" Could someone help on this. Thank you...

CodePudding user response:

We can simply convert the input to a "normal" time:

SELECT CONVERT(intime, TIME) AS intime 
FROM yourtable;

If we don't want to select only, but to execute an update, this will do:

UPDATE yourtable 
SET intime = CONVERT(intime, TIME);

If we want to alter the table and change the column to a "normal" time, whis will do:

ALTER TABLE yourtable MODIFY intime TIME;

If we then do inserts like this...

INSERT INTO yourtable VALUES ('17:44:58.2555247');

...and select from the table, the output will be 17:44:58

  • Related