• Since you are on SQL2008, you can forget about TRY_CAST since this is a SQL2012 feature only.

    On SQL2008 you could use a CASE expression to guard the expression evaluation to avoid this issue.

    Like this:

    UPDATE#t2

    SETTTT_Factureren = 0,

    TTT_FactuurStatus = 0,

    TTT_FactuurNummer = 0

    WHERETTT_ProjectID = 26

    AND TTT_FactuurStatus = 1

    AND TTT_ID NOT IN(

    SELECT

    CASE WHEN X.TextDescription LIKE 'Int.nr.TXT:%'

    THEN CAST(SUBSTRING(CAST(X.TextDescription AS VARCHAR(100)),13,10) as int)

    ELSE -1

    END

    FROM #t1 X

    WHERE X.TextDescription LIKE 'Int.nr.TXT:%'

    )

    Note the use of LIKE which gives much better performance than SUBSTRING in the predicate

    This method is also more efficient than casting TTT_ID to a varchar since it is much faster to compare integers than strings.

    Good luck