I’m selecting a value out of a table that can either be an integer or a nvarchar. It’s stored as nvarchar. I want to conditionally call a function that will convert this value if it is an integer (that is, if it can be converted into an integer), otherwise I want to select the nvarchar with no conversion.
This is hitting a SQL Server 2005 database.
select case when T.Value (is integer) then SomeConversionFunction(T.Value) else T.Value end as SomeAlias from SomeTable T
Note that it is the ‘(is integer)’ part that I’m having trouble with. Thanks in advance.
UPDATE
Check the comment on Ian’s answer. It explains the why and the what a little better. Thanks to everyone for their thoughts.
Also, have you considered using the sql_variant data type?