You can try to create computed columns in case you are not allowed or able to populate the columns on write/update:
CREATE TABLE DataSource
(
ID INT PRIMARY KEY
,BPValue VARCHAR(12)
)
GO
INSERT INTO DataSource (ID, BPValue)
VALUES (1, '123/98')
,(2, '118/72')
,(3, '97/74');
GO
ALTER TABLE DataSource
ADD Value1 AS TRY_CAST(SUBSTRING(BPValue, 0, CHARINDEX('/', BPValue)) AS INT)
ALTER TABLE DataSource
ADD Value2 AS TRY_CAST(SUBSTRING(BPValue, CHARINDEX('/', BPValue) + 1, 128) AS INT)
GO
SELECT *
FROM DataSource
Also, the columns can be materialized if you create them with the PERSISTED option. Otherwise, the computation is perform on read, which can be slow on certain cases.
The better way, is to create two separate columns and populate the data on insert/update.
The above can be done on MySQL , too. Here is the link to the official documentation.
3条答案
按热度按时间iih3973s1#
here is a hack using
parsename
Output
ipakzgxi2#
You can use ALTER to do that.
Example:
41zrol4v3#
You can try to create computed columns in case you are not allowed or able to populate the columns on write/update:
Also, the columns can be materialized if you create them with the
PERSISTED
option. Otherwise, the computation is perform on read, which can be slow on certain cases.The better way, is to create two separate columns and populate the data on insert/update.
The above can be done on MySQL , too. Here is the link to the official documentation.