views:

26

answers:

1

SQL Server CE (3.5) doesn't appear to support the IsNumeric function. What are some alternatives to achieve the same functionality? Specifically, how would you test whether a CAST from a string to a DECIMAL datatype will succeed in SQLCE without IsNumeric?

A: 

One possibility is to explicitly add an ISNUMERIC column to the table, and set the value (in your code, using your own method or a built-in .NET method) whenever the row is added or updated.

Another possibility is to use a query like this:

SELECT * FROM tbl WHERE col LIKE '%[^0-9]%'
MusiGenesis
Typically what `IsNumeric`, `IsDate` and their ilk are used for is for making sure a `CAST` will succeed, and providing a reasonable default if it doesn't. You'd need to support initial negative signs and decimals and potentially the 'e' notation, and with all those considerations the statement becomes huge. Sure, a big-fat-brute-force `case` statement would get the job done, but I'm hoping there's something more, uh, reasonable already built in.
mattmc3