INSERT INTO tbl_LandRigs ([Company], [Rig], [RigType], [DrawWorks], [TopDrive])
VALUES (@Company, @Rig, @RigType, @DrawWorks, CASE WHEN ISNUMERIC(@TopDrive) = 1 THEN @TopDrive ELSE 0 END)
Here we are putting both CASE
and ISNUMERIC
to good use.
Also, it usually makes it easier for other developers (or yourself at a later date) to be consistent with your usage of brackets and white space, even in SQL code.
As mentioned by others, isnumeric
may give you some false positives. If possible, it's often best to sanitize the input before it gets to your database, perhaps by not using untyped data in this case. Only you know your inputs, but if you anticipate a problem, there are some options.