declare @input varchar(255) = 'abc' select * from table where id = CAST(@input as int)
Can I make it so that the cast doesn’t work out quietly or is set to any user-defined default (or system default)?
Denali has try_convertand try_parsefunctions.
try_convert
try_parse
Until then you can use
DECLARE @input VARCHAR(11) = 'abc' SELECT * FROM table WHERE id = CAST(CASE WHEN @input NOT LIKE '%[^0-9]%' THEN @input END AS INT)
(, int), (, ) CASE, , CASE .
CASE
TRY-CATCH CATCH .
TRY-CATCH
CATCH