Solved

Sql string manipulation

Posted on 2007-11-20
2
501 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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

763 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

14 Experts available now in Live!

Get 1:1 Help Now