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

  • SEARCH
  • Home
  • 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 1093777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:52:30+00:00 2026-05-16T23:52:30+00:00

I want to write a stored procedure that queries XML files after I have

  • 0

I want to write a stored procedure that queries XML files after I have input a certain string pattern to look for.

I’m already stuck at the input parameters, consider the following XML-document.

<root>
  <container>
      <element>A</element>
      <option>1</option>
  </container>
  <container>
      <element>B</element>
      <option>-1</option>
  </container>
  <container>
      <element>C</element>
  </container>
</root>

What I want to achieve is find and output a certain pattern combining element-tag and option-tag to a table.

For example: EXEC search “A1,B-1,C” is the input string and would be true which then needs to be put in a table. But “A,B,C” would be false.

I’m not that great with TSQL, so I don’t know how I could split or arrange the search pattern so that I could use this to work with both element-tag and option-tag and put them into variables or so.

EDIT: The code below I think is going in the right direction but I have another big issue.
I need to analyze each value of the pattern with a corresponding table.

I better give an example: Input is “A1,B-1,C” btw input length should be flexible.

In my existing table I have 4 columns with the following data:

  ID| Value | Meaning | Info
  1 |   A   |   text  | text
  2 |   A-1 |   text  | text
  3 |   A1  |   text  | text
  4 |   B   |   text  | text
  5 |   B-1 |   text  | text

and so on…

Now somehow I need to check each single input-string with the value and output the input-string with both “Meaning” and “Info” column to another table.

With the example above I would have to find the sequence of “A1,B-1,C” and then output the corresponding text (including the string) of the table above to a new table.
So that it could look like this:

  | Value | Meaning | Info
  |   A1  |   text  | text
  |   B-1 |   text  | text
  |   C   |   text  | text

I don’t know if I’m making it too complicated with the above table or if a CASE / IF-ELSE structure in the procedure would work better.

Does anyone know how this can be achieved?

  • 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. Editorial Team
    Editorial Team
    2026-05-16T23:52:31+00:00Added an answer on May 16, 2026 at 11:52 pm

    It looks as if you’re using the wrong tools for the job but if these are pretty firm constraints you’re working against then you could use the following, for example:

    drop table #xml
    drop table #queryparams
    
    declare @x xml
    select @x = '<code><root><items><element>A</element><option>1</option></items><items><element>B</element><option>-1</option></items><items><element>C</element></items></root></code>'
    
    create table #xml (element varchar(60), [option] int null)
    
    insert into #xml
    select code.item.value('(element)[1]', 'varchar(60)'),
      code.item.value('(option)[1]', 'int')
    from 
      @x.nodes('/code/root/items') AS code(item)
    
    declare @queryParam varchar(60)
    select @queryParam = 'A1,B-1,C'
    
    create table #queryparams (element varchar(60), [option] int null)
    
    insert into #queryparams
    select left(data,1), RIGHT(data, len(data)-1) 
    from dbo.split(@queryParam,',')
    
    if not exists (
     select *
     from #xml x
     left join #queryparams q
      on x.element = q.element
     where q.[option] is null
    )
    select 1
    else
    select 0
    

    As marc_s suggests you’re better off with <element> and <option> tags inside a common tag. I’ve opted for the poorly named <items> in this case.

    This solution is nasty enough to suggest the approach isn’t quite right somehow.

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

Sidebar

Related Questions

I want to write a stored procedure that works something like this: SELECT *
I'm trying to write a stored procedure that will have 6 bit value flags
I want to write a stored procedure that will accept a parameter of @searchString.
I want to write a stored procedure to increment the value of an int
I want to create generic function that will need only parameter as Stored procedure
I want to write a command that specifies the word under the cursor in
I want to write a little DBQuery function in perl so I can have
I want to write a function in Python that returns different fixed values based
I want to write a function that takes an array of letters as an
I want to write a word addin that does some computations and updates some

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.