Solved

Sql string manipulation

Posted on 2007-11-20
2
507 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 250 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

691 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