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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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 SpecialistCommented:
Probably not. SSMS is not meant as a tool to enter data, that should happen in the front-end application.

You can try Heidi
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.

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.
Shaun VermaakTechnical SpecialistCommented:
Yes, an update query would be best. Please explain your steps in a bit more detail with screenshots
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

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

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

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)

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.
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

       , SUBSTRING(ct.EvFullContent, ct.StartAt+1, pos.EndAt-ct.StartAt-1) AS MatchedString
          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

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.
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.