How to parse data in the middle of the value returned

Posted on 2007-08-08
Last Modified: 2013-11-05
In SQL Server 2005 Reporting Services I have a queried field that has a value like this:|PurchasePlan=12345|License=licensenumber

I need the value returned to only be the '' part. In other words just the part after 'Customer=' and before the'|PurchasePlan=' parts These values are always included in the data.
Question by:brooksmato
    LVL 30

    Expert Comment

    If the format is consistent (i.e. always in that sequence):

    DECLARE @Str varchar(1000)
    SELECT @Str = '|PurchasePlan=12345|License=licensenumber'
    SELECT SUBSTRING(@Str,10,CHARINDEX('|',@Str,10)-10)
    LVL 30

    Accepted Solution

    this should work if the format is not consistent:

    DECLARE @Str varchar(1000)
    SELECT @Str = '|PurchasePlan=12345|License=licensenumber'
      SUBSTRING(@Str, CHARINDEX('Customer=', @Str) + 9,
        CASE WHEN CHARINDEX('|', @Str, CHARINDEX('Customer=', @Str)) = 0 THEN LEN(@Str)
          ELSE CHARINDEX('|', @Str, CHARINDEX('Customer=', @Str)) - (CHARINDEX('Customer=', @Str) + 9)  
    AS [Customer]

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now