TSQL Get Data between [ brackets ]

Hello all,

In SSMS, when you
Right Click "Edit All Rows"

When you click on a column, it will jump to the end of the text in that column.
Is there a way, to make it jump to the beginning of the column, instead of the end?
LVL 31
Wayne BarronAuthor, Web DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical Specialist/DeveloperCommented:
Probably not. SSMS is not meant as a tool to enter data, that should happen in the front-end application.

You can try Heidi
https://www.heidisql.com/download.php
0
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Explanation of why I was asking.
I have several hundred records that I need to go through.
I am looking for the tag in each and every row.
[proimge=image.jpg]

Open in new window

I am then going to take that value, and place it in a new column for the image.

So, I was going to just go through each record and update it manually.
I think a better way would be to run a query for everything between the brackets.
Return all rows, and then copy the data over to the new column.

Any ideas on this would be great.
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Yes, an update query would be best. Please explain your steps in a bit more detail with screenshots
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Wayne BarronAuthor, Web DeveloperAuthor Commented:
I just found this and modified it, and it returns all records.
however, it cuts off some of the content.

select EVID, evTitle, SUBSTRING(evFullContent,CHARINDEX('[proimg=',evFullContent)+1,CHARINDEX(']',evFullContent) - CHARINDEX('[',evFullContent)-1) from evContent

Open in new window


Using the code above, the following happens.
This record
[proimg=carrzkiss/carrzkiss_02-58-55-Jul-14-2012_carrzkiss_02-34-52-Jun-11-2011_EnterView_.png]EnterView - Connecting Entertainment and the views of the world together![/proimg]

Open in new window

Will return this value
proimg=carrzkiss/carrzkiss_02-58-

Open in new window


This record
[proimg=carrzkiss/carrzkiss_02-57-25-Jul-14-2012_carrzkiss_01-09-41-Mar-01-2011_logo.jpg]Carrz-Fox-Fire Promotions[/proimg]

Open in new window

Will return this value
proimg=carr

Open in new window


However, this record.
[proimg=carrzkiss/carrzkiss_02-57-26-Jul-14-2012_carrzkiss_07-04-59-Mar-23-2011_Logo.png]Dark Effects Productions[/proimg]

Open in new window

Will return this value (The correct value)
proimg=carrzkiss/carrzkiss_02-57-26-Jul-14-2012_carrzkiss_07-04-59-Mar-23-2011_Logo.png

Open in new window


So, it seems the code works, but does not give the correctly expected results.

NOW, keeping in mind.
The code has a LOT of BRACKETS in it.
0
_agx_Commented:
Update:  Modified to only exclude leading and trailing "[" and "]"

If the column contains more than just that image string, the 2nd CHARINDEX should search for the next instance of "]" AFTER the position of the first [proimg=".  Something like this

SELECT *
       , SUBSTRING(ct.EvFullContent, ct.StartAt+1, pos.EndAt-ct.StartAt-1) AS MatchedString
FROM  (
          SELECT *, CHARINDEX('[proimg=', evFullContent) AS StartAt
          FROM  evContent
       ) ct 
       CROSS APPLY ( 
         SELECT CHARINDEX(']',ct.evFullContent, ct.StartAt)) pos(EndAt)
WHERE ct.StartAt > 0     
AND   pos.EndAt > 0

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Worked great.
Thank you very much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.