I need to create a simple view containing a driverID that must be converted
to numeric.
IF isnumeric(driverID) = 0 then 0
I tried to use IIF(isnumeric(driverID), driver, 0) but it's not accepted in
regular query.
Please help!
Thanks
BillYou can use a CASE expression; For example:
SELECT
CASE WHEN ISNUMERIC(DriverID) = 1 THEN DriverID ELSE 0 END
FROM MyTable
Note that ISNUMERIC can return 1 for values you might not want to consider
as numeric (e.g. '1E0') so you might want to substitute LIKE:
SELECT
CASE WHEN DriverID NOT LIKE '%[^0-9]%' THEN DriverID ELSE 0 END
FROM MyTable
Hope this helps.
Dan Guzman
SQL Server MVP
"Bill nguyen" <billn_nospam_please@.jaco.com> wrote in message
news:ekpb7A%231FHA.3660@.TK2MSFTNGP15.phx.gbl...
>I need to create a simple view containing a driverID that must be converted
>to numeric.
> IF isnumeric(driverID) = 0 then 0
> I tried to use IIF(isnumeric(driverID), driver, 0) but it's not accepted
> in regular query.
> Please help!
> Thanks
> Bill
>
No comments:
Post a Comment