Home > Software design >  I get an error : MSG529, Level 16, State 2, Line 116 Explicit conversion from data type time to int
I get an error : MSG529, Level 16, State 2, Line 116 Explicit conversion from data type time to int

Time:04-02

Please assist me here. I get error:

Msg 529, Level 16, State 2, Line 116
Explicit conversion from data type time to int is not allowed.

When I try to convert time column into int.

select convert( int , TrainDirectionCode) from [Rail_Equipment_Accident_Incident_Data 2]

I need to get this Extra long column to show just 1 or 2 or 3 or 4.

Column

Currently I have format: 04:00:00.0000000

CodePudding user response:

You can use the hour() function to extract only the hour from your time column.

CodePudding user response:

First of all, this looks a lot more like SQL Server than MySQL...

In either case, there's no direct conversion from a Time value to an Int value. After all, what integer does 04:00:00.0000000 represent? 4? 400? 14,400? Why?

If this is indeed SQL Server then it sounds like what you're looking for is the DATEPART function to extract a specific "part" of the value. Something like this:

SELECT DATEPART(hour, [TrainDirectionCode]) FROM [Rail_Equipment_Accident_Incident_Data 2]
  • Related