jeevan
3/27/2007 4:59:00 AM
IsNumeric will return 1 if you include a sign (like "-100"), a decimal point
(like "10.8"), an exponent (like "6.3E+34") or even this: "10D9". Be
careful.
User-defined functions have special restrictions on them concerning "side
effects" in the database. The fact that you can't handle errors in them is
probably an extension of that prohibition. If you think you need the
error-handling functionality, consider using an SP instead.
"Jeremy" <jeremy-nospam@ninprodata.com> wrote in message
news:O2ZyhnvbHHA.596@TK2MSFTNGP06.phx.gbl...
> Gentlemen, thanks. After I posted, I remembered isNumeric(), which seems
> to work wonderfully. Still, it would be good to have try/catch in the
> toolbox.
>
> Jermey
>
> "Tom Cooper" <tomcooper@comcast.no.spam.please.net> wrote in message
> news:OLGHXUpbHHA.2088@TK2MSFTNGP04.phx.gbl...
>> And allow for the case where @input is less than 3 characters long, like
>> '25'
>>
>> SET @value = CASE WHEN Right('00' + @input, 3) LIKE '[0-9][0-9][0-9]'
>> THEN CAST (@input AS INTEGER)
>> ELSE NULL END
>>
>> Tom
>>
>> "Mike C#" <xyz@xyz.com> wrote in message
>> news:OXCJ8wobHHA.4888@TK2MSFTNGP06.phx.gbl...
>>> Validate the @input using LIKE before you do anything with it.
>>>
>>> SET @value = CASE WHEN @input LIKE '[0-9][0-9][0-9]' THEN CAST (@input
>>> AS INTEGER)
>>> ELSE NULL END
>>>
>>> "Jeremy" <jeremy-nospam@ninprodata.com> wrote in message
>>> news:e9I9wmjbHHA.2552@TK2MSFTNGP06.phx.gbl...
>>>> Try-Catch blocks aren't allowed in user functions. What do you do
>>>> instead?
>>>>
>>>> I'm writing a function that casts the input as follows
>>>>
>>>> declare @input as varchar(3)
>>>> cast (@input as integer)
>>>>
>>>> I'd really like to gracefully handle cases where the input data is
>>>> screwed up.
>>>>
>>>> Jeremy
>>>>
>>>
>>>
>>
>>
>
>