How can I use ISNUMERIC() function with sql_variant datatype?
This following code doesn't work
DECLARE @x sql_variant
SET @x = 3
IF ISNUMERIC(@x) = 1
SELECT 'Numeric'
ELSE
SELECT ' NOT'
Error :
Msg 8116, Level 16, State 1, Line 4
Argument data type sql_variant is invalid for argument 1 of isnumeric function.
But this works
IF ISNUMERIC(CAST(@x AS INT)) = 1
is there is any way of making this happened with out CAST()
Haven't found any thing useful on google regarding this issue thanks , I'm using SQL Server 2008 R2
Casting to int doesn't really make sense. Your conversion will fail (when something else than an integer appears) and you'll get an error.
You can, however, cast to nvarchar(max) - this should always work and your ISNUMERIC function will behave as expected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With