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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:41:26+00:00 2026-06-02T01:41:26+00:00

I have the typical table: LSRNbr BatchNbr 111 1212 111 1414 And the query

  • 0

I have the typical table:

LSRNbr  BatchNbr
111     1212
111     1414  

And the query should return:

LSRNbr   BatchNbr
111      1212, 1414

I was browsing for a solution to this and I found these two:

Solution 1:

;WITH C AS 
(
SELECT LSRNbr, BatchNbr FROM tblDTS_LSRBatch
)

SELECT Distinct LSRNbr, 
STUFF((SELECT ';' + BatchNbr FROM tblDTS_LSRBatch WHERE LSRNbr = c.LSRNbr FOR XML PATH('')),1,1,'') 
FROM C

error:

Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ';'.
Msg 170, Level 15, State 1, Line 7
Line 7: Incorrect syntax near 'XML'.

Solution 2:

SELECT 
[LSRNbr], REPLACE(RTRIM((SELECT [BatchNbr] + ' ' FROM tblDTS_LSRBatch WHERE (LSRNbr = Results.LSRNbr ) FOR XML PATH (''))),' ',', ') AS NameValues
FROM tblDTS_LSRBatch Results
GROUP BY LSRNbr

error:

Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'XML'.

But none of them worked for me, see errors above please.

What could be the problem here?

I’m using Microsoft SQL Server 2005

  • 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-02T01:41:27+00:00Added an answer on June 2, 2026 at 1:41 am

    These are syntax errors.

    You’ll learn more from figuring out the particular error yourself:

    Take a look at the syntax tree

    Take a look at some good examples of what you’re trying to do

    If you still have trouble, feel free to ask more questions

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

Sidebar

Related Questions

Suppose you have this table structure: Patient -> PatientTag -> Tag A typical N:M
I have this table that represents a weak entity and is a typical table
I have a typical N-M relationship structure like this: two independent tables: Table Client:
I have the typical emp table from which i want to fetch the hierarchical
Say I have a typical customer table; Id Int Identity Primary Key, FirstName varchar(255),
I have a table set up as follows id origin destination carrier_id so typical
I have a self-referencing table with an Id, CategoryName, and ParentId. It's a typical
Say I have a table called Users, which contains your typical information: Id, Name,
What is the typical way to weigh results in MYSQL? I have a table
I have a typical Persons table and an Orders table defined in such a

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.