Home Forums SQL Server 2008 T-SQL (SS2K8) How to parse connection strings on a column in SQL Server 2008 RE: How to parse connection strings on a column in SQL Server 2008

  • You can expose pretty much any parameter you want regardless of position using a pattern-based string splitter like this:

    WITH SampleData (ID, ConnectionString) AS

    (

    SELECT 1, 'server=SVR1;database=DB1;uid=user1;pwd=pass1;enlist=true'

    UNION ALL SELECT 2, 'database=DB1;server=SVR1;uid=user1;pwd=pass1;enlist=true'

    UNION ALL SELECT 3, 'server=SVR1;uid=user1;pwd=pass1;database=DB1;enlist=true'

    ),

    Params AS

    (

    SELECT *

    FROM SampleData

    CROSS APPLY PatternSplitCM(ConnectionString, '[;=]')

    WHERE [Matched]=0

    )

    SELECT ID, dbname=Item

    FROM Params a

    WHERE ItemNumber =

    (

    SELECT 2+ItemNumber

    FROM Params b

    WHERE a.ID = b.ID AND b.Item = 'database'

    );

    PatternSplitCM is a utility function that can be found in the 4th article in my signature links.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St