On SQL Server 2012 you can use TRY_CONVERT
.
This is more reliable than isnumeric
for this purpose.
ALTER TABLE dbo.Tabla
ADD ParsedValue AS ISNULL(TRY_CONVERT(decimal(18, 4), StringValue), 0) PERSISTED
I would consider not making it PERSISTED
and not wrapping it in ISNULL
for non numeric values though.
Treating non numeric values as 0
rather than NULL
will mean that, for example, AVG
calculations are not correct.
It is not necessary to mark it as PERSISTED
to create an index on this column.