• Edit: misinderstood the requirement. Updated my function accordingly...

    With the DelimitedSplit8K[/url] splitter function you could create an inline Table Valued function like this:

    CREATE FUNCTION dbo.string_to_table(@string varchar(8000))

    RETURNS TABLE

    AS

    RETURN

    (

    SELECTLEFT(item, CHARINDEX(' ',item)) AS customer_id,

    RIGHT(item, LEN(item)-CHARINDEX(' ',item)) AS customer_address

    FROM (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)), item

    FROM dbo.DelimitedSplit8K(@string,CHAR(10))) x(rn, item)

    WHERE rn>1

    )

    GO

    Then you could do something like this:

    DECLARE @string varchar(200)=

    'Customer ID Address

    6237 025 OHIO DR APT 13111

    9261 123 main street #1567

    8036 12 lee street #8956345';

    SELECT *

    FROM dbo.string_to_table(@string)

    WHERE customer_address LIKE N'%[0-9][0-9][0-9][0-9][0-9][0-9]%'

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001