You could write a table-valued UDF that takes the strings as input and returns the items in separate rows of a table. Something like this (not the most efficient thing in the world...):
CREATE FUNCTION [dbo].[SplitMyValues]
(
@Input VARCHAR(MAX)
)
RETURNS @Results TABLE
(
Data VARCHAR(MAX)
)
AS
BEGIN
DECLARE @Where INT
DECLARE @Length INT
DECLARE @Next INT
SET @Where = 0
SET @Length = LEN(@Input)
WHILE (@Where < @Length)
BEGIN
SET @Next = CHARINDEX(' ', @Input, @Where)
IF (@Next > 0)
BEGIN
INSERT INTO @Results VALUES (SUBSTRING(@Input, @Where, @Next - @Where))
SET @Where = @Next + 1
END
ELSE
BEGIN
INSERT INTO @Results VALUES (SUBSTRING(@Input, @Where, LEN(@Input)))
SET @Where = @Length
END
END
RETURN
END
To see the output, you can just run this:
SELECT *
FROM
dbo.SplitMyValues('7864750A 7888801BZ 5189748C 3218833H')
Then you can just do a join or a subquery in the WHERE
clause of an UPDATE
or SELECT
, like:
SELECT *
FROM
SomeTable S
INNER JOIN dbo.SplitMyValues('7864750A 7888801BZ 5189748C 3218833H') X
ON X.Data = S.WhateverColumn