Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 180707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:38:02+00:00 2026-05-11T14:38:02+00:00

having trouble coming up with search parameters for this issue, so I can’t find

  • 0

having trouble coming up with search parameters for this issue, so I can’t find an answer on my own.

       Column X             |       Message (info 1)           | Message (info 2) (info 1)  | 

Above is the contents of one column I need to handle. The result of the query should be the part INSIDE the parentheses only. Problem is, there’s one program that saves two sets of information in parentheses, in which case the LATTER (info 1) is the one we want in the first column, in addition to which we must add a second column for info 2.

So I’m imagining I need to combine an if clause with a variable I can depend on to count how many left parentheses there are, for example. If left_parentheses = 2, Then …. Else If left_parentheses = 1, Then ….

But I don’t know how to do that in SQL, and I also don’t know how to separate between info 1 / 2 in the example.

The result from the example would look like this:

 Column 1 | Column 2  Info 1  |  Info 1  |  Info 2 

As usual, I’ll try to look for the answer while waiting for tips here. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:38:02+00:00Added an answer on May 11, 2026 at 2:38 pm

    Here’s my go at it in SQL 2005 syntax using a Common Table Expression. I make no claims as to it’s correctness or it’s efficiency and I’ve made some assumptions about how you wanted it to work.

    WITH BracketIndeces AS (   SELECT      ColumnX AS ColVal,     CHARINDEX('(', ColumnX) as first_open_bracket,     CHARINDEX('(', ColumnX, CHARINDEX('(', ColumnX)+1) as second_open_bracket,     CHARINDEX(')', ColumnX) as first_close_bracket,     CHARINDEX(')', ColumnX, CHARINDEX(')', ColumnX)+1) as second_close_bracket   FROM SomeTable ) SELECT   CASE     WHEN second_close_bracket = 0 THEN         SUBSTRING(ColVal, first_open_bracket+1, first_close_bracket - first_open_bracket-1)     ELSE         SUBSTRING(ColVal, second_open_bracket+1, second_close_bracket - second_open_bracket-1)         END AS Column1,   CASE     WHEN second_close_bracket = 0 THEN         NULL     ELSE         SUBSTRING(ColVal, first_open_bracket+1, first_close_bracket - first_open_bracket-1)   END AS Column2 FROM BracketIndeces WHERE first_open_bracket <> 0 AND first_close_bracket <> 0 AND first_open_bracket < first_close_bracket AND (   (second_open_bracket = 0 AND second_close_bracket = 0)    OR   (second_open_bracket < second_close_bracket      AND second_open_bracket > first_close_bracket   ) ) 

    The where clause at the bottom is just to filter out any columns that either contain no brackets or contain brackets in a weird order and it uses NULL in Column2 when only one set of brackets are there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble coming up with a query that will find all customers who
I'm having trouble coming up with a solution for the following issue. Lets say
I'm having trouble coming up with this solution logically. I have an accounts table
I'm having trouble coming up with a working query for this situation... Table: [
I'm having trouble wrapping my brain around this select statement. The data is coming
I'm having trouble coming up with the correct regex string to remove a sequence
I'm having trouble coming up with the proper syntax for allowing either a string
I'm having trouble coming up with a solution for the following problem and i
I'm coming from Java/C++ to Ada and am having trouble figuring out the small
I am having trouble coming up with a jQuery script that will all content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.