February 12, 2009 at 8:48 am
I've got lines in the db like
UserLogon Logon "Domain\Username" from blah
UserLogon Logon "Domain\Username2"
I only want the data in the "'s, but can't figure out how to write the split or whatever which thinks the " is identifying text.
February 12, 2009 at 9:23 am
-- *** Test Data ***
DECLARE @t TABLE
(
    Line varchar(50) NOT NULL
)
INSERT INTO @t
SELECT 'UserLogon Logon "Domain\Username" from blah' UNION ALL
SELECT 'Junk' UNION ALL
SELECT '"Junk2' UNION ALL
SELECT 'UserLogon Logon "Domain\Username2"'
-- *** End Test Data ***
SELECT SUBSTRING(Line, StartPos, EndPos - StartPos) AS AccountName
FROM
(
    SELECT *
        ,CHARINDEX('"', Line, StartPos) AS EndPos
    FROM
    (
        SELECT
            Line
            ,CHARINDEX('"', Line) + 1 AS StartPos
        FROM @t
    ) D1
    WHERE StartPos > 1
) D
WHERE EndPos > 0
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply