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 8031435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:05:57+00:00 2026-06-05T01:05:57+00:00

Usually I use a XML variable in filters, because they are easy to work.

  • 0

Usually I use a XML variable in filters, because they are easy to work.

Considering tablea, where column1 is the primary key:

declare @xml xml = '<column1>1</column1><column1>2</column1>'

select *
from tablea
where
    column1 in (select x.i.value('.', 'bigint') from @xml.nodes('/column1') x(i)) or
    @xml is null

It works because the select over the xml returns two rows, with values 1 and 2.

Now I have a tableb, with a composite primary key, column1 and column2. So:

declare @xml xml = '<row><column1>1</column1><column2>2</column2></row><row><column1>3</column1><column2>4</column2></row>'

How can I write a select over the xml to return each row and columns, like:

column1 column2
1       2
3       4
  • 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-06-05T01:05:58+00:00Added an answer on June 5, 2026 at 1:05 am
    declare @xml xml = '<row><column1 a="a">1</column1><column2>2</column2></row><row>' +
        '<column1>3</column1><column2>4</column2></row>'
    
    select  col.value('data(column1[1])', 'int') as column1
    ,       col.value('data(column2[1])', 'int') as column2
    from    @xml.nodes('/row') tbl(col)
    

    Example at SQL Fiddle.

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

Sidebar

Related Questions

I usually use SELECT 1 as my preferred validation-query from tomcat jdbc pools, because
I need to transform a XML. Usually I would use Saxon and a XSLT
I usually use one preference XML file to store all app-wide data. Now I
I have just started using XML as I usually use php but I am
I'm writing my own wrapper class for parsing XML data. Usually I use the
I usually use this code to add item from datebase to list view: public
I usually use Visual Studio Team System 2008 Source Control Explorer with TFS, but
I usually use the following pipeline to grep for a particular search string and
I usually use this line to import file from out of the current folder
I usually use pointers in the following manner char *ptr = malloc( sizeof(char) *

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.