I wish to cast VARCHAR to INT, however in my table i've some value like '???' then SQL Server launch this expcetion :

Conversion failed when converting the varchar value '????' to data type int.
Severity 16

I possibly could convert this '???' to NULL, that's not a problem, but exactly how do this ?

I am trying to behave such as this:

INSERT INTO labbd11..movie(title, year)
SELECT movies.title, 
       CASE movies.mvyear IS '????' THEN NULL ELSE CAST (movies.mvyear AS INT)
FROM disciplinabd..movies

But nothing works ..

Any ideas men ?

In my opinion you'd want something similar to

INSERT INTO labbd11..movie(title, year) 
  SELECT movies.title, 
         CAST( CASE movies.mvyear 
                    WHEN '????' THEN NULL 
                    ELSE movies.mvyear
                 END AS INT) 
    FROM disciplinabd..movies

You would like your Situation statement to come back a VARCHAR (either the MVYEAR or NULL) and you want the CAST to function on caused by the Situation.

You may would like to solve this generally and cope with any non-int value exactly the same way

 INSERT INTO labbd11..movie(title, year) 
    SELECT movies.title, 
           CASE WHEN IsNumeric(movies.mvyear+ '.0e0') <> 1  THEN NULL 
                ELSE CAST (movies.mvyear AS INT) END  
      FROM disciplinabd..movies

Check this out question

    INSERT INTO labbd11..movie(title, year) 
    SELECT movies.title, 
           CASE WHEN movies.mvyear = '????' THEN NULL 
                ELSE CAST (movies.mvyear AS INT) END  
      FROM disciplinabd..movies
INSERT INTO labbd11..movie(title, year)
    SELECT
        movies.title,
        CAST(CASE WHEN movies.mvyear = '????' THEN NULL ELSE movies.mvyear END AS INT)
    FROM
        disciplinabd..movies

You may also use CAST(NULLIF(movies.mvyear,'????') AS INT)