I am using SQL Server 2008. Is there a way I can create computed column (deterministic) by extracting only numerical value from another alphanumeric column in the same table? and then index it?
For example, in my table tblVendorShippingInfo
I have a column PONum
what is alphanumeric, data type VARCHAR
.
I tried to create a function and added the column (below)
ALTER FUNCTION [dbo].[Calc_GetPOID] (@strText VARCHAR(100))
RETURNS INT
AS
BEGIN
WHILE PATINDEX('%[^0-9]%', Left(@strText, 8) ) > 0
BEGIN
SET @strText = STUFF(@strText, PATINDEX('%[^0-9]%', @strText), 1, '')
END
RETURN Left(@strText,8)
END
-- Add the computed column
ALTER TABLE tblVendorShippingInfo
ADD POID AS dbo.[Calc_GetPOID](PONum)
When I tried to add an index for POID computed column, it prompted error something related to "cannot add because it is non-deterministic column"...
Any suggestions to make it deterministic and indexable?