Jaylen Jaylen - 1 month ago 13
SQL Question

SQL, How to convert VARCHAR to bigint?

I have a field that is

VARCHAR(6)
I am trying to insert it into another table of type
bigint
it is giving me an error

(Error Converting from data type varchar to bigint

here is what i am doing

CONVERT(bigint, seconds) as seconds


Can anybody help with this issue?

Answer

This is the answer

(CASE
  WHEN
    (isnumeric(ts.TimeInSeconds) = 1) 
  THEN
    CAST(ts.TimeInSeconds AS bigint)
  ELSE
    0
  END) AS seconds
Comments