[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sql string manipulation

Posted on 2007-11-20
2
Medium Priority
?
510 Views
Last Modified: 2013-11-15
Out of string -
\\servr1\Reports\Temp\Big_Ticket_Posting.rpt^\\servr\DF^Start_Date=2/2/2007;End_Date=2/2/2007;Compensation=ALL;Channel=ALL;Territory=W06;^test@test.com^Big Ticket Posting^PDF

How can I parse ( select ) out by Sql 2005 parameters and their values. End result I need is:
Start_Date=2/2/2007;End_Date=2/2/2007;Compensation=ALL;Channel=ALL;Territory=W06
I tried with charindex() no avail. Thanks for help!
0
Comment
Question by:ivan_belal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Expert Comment

by:pai_prasad
ID: 20323476
DECLARE @QueryStr varchar(1024)
                  ,@startPosition int
                  ,@endPosition int

SELECT @queryStr = '\\servr1\Reports\Temp\Big_Ticket_Posting.rpt^\\servr\DF^Start_Date=2/2/2007;End_Date=2/2/2007;Compensation=ALL;Channel=ALL;Territory=W06;^test@test.com^Big Ticket Posting^PDF
'
Select @startPosition  =  charindex('^',@querystr,charindex('^',@querystr)+1)
Select @endPosition    =  charindex('^',@querystr,@startPosition+1)

SELECT @startPosition, @endPosition

Select substring(@queryStr,@startPosition+1,(@endPosition-@startPosition)-1)
0
 
LVL 25

Accepted Solution

by:
imitchie earned 1000 total points
ID: 20323527
single select

declare @s varchar(max) set @s =
'\\servr1\Reports\Temp\Big_Ticket_Posting.rpt^\\servr\DF^Start_Date=2/2/2007;End_Date=2/2/2007;Compensation=ALL;Channel=ALL;Territory=W06;^test@test.com^Big Ticket Posting^PDF'

select substring(left(@s, len(@s) - charindex(';', reverse(@s))), 1+charindex('=', @s) -
charindex('^', reverse(left(@s, charindex('=', @s)-1))), len(@s))

assumptions:
the first "=" is after the first parameters
the last ";" ends the parameters
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 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