Solved

Sql string manipulation

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

911 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