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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:20:52+00:00 2026-06-06T06:20:52+00:00

I am using SQL Server 2008. This are my tables. Table A Aid int

  • 0

I am using SQL Server 2008.

This are my tables.

Table A

 Aid int pk
 col2
 col3
 XYZID int

Table B

 Bid int pk
 XYZID int
 Col2
 Col3 
 Col4
 seq -- (Sequence )

Table B will be like this

seq   col2    |XYZID|Bid |col3| col4 
===============================================
  1   foo     | 1   |  1 | 12 | wqw
  3   bar     | 1   | 10 | 77 | kikk
  2   foobar  | 1   |  2 |  w | ed
  1   barfoo  | 2   |  4 |  e | dwe
  2   asdsad  | 2   |  5 |  e | e 

Table A is the main table and based on the XYZID in A

I need to generate a string value using col from TableB with XYZID and Seq .

I need to generate a string value using col from TableB with XYZID and Seq .

For eg: xyzid= 1

I expected : foo-12-wqw#foobar-w-ed#bar-77-kikk

based on Sequence foo-1,foobar-2,bar-3

  • 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-06T06:20:55+00:00Added an answer on June 6, 2026 at 6:20 am

    For XYZID = 1.

    select stuff((select '#'+col2+'-'+col3+'-'+col4
                  from TableB
                  where XYZID = 1
                  order by seq
                  for xml path(''), type).value('.', 'nvarchar(max)'), 1, 1, '')
    

    For all rows in TableA:

    select stuff((select '#'+col2+'-'+col3+'-'+col4
                  from TableB as B
                  where A.XYZID = B.XYZID
                  order by seq
                  for xml path(''), type).value('.', 'nvarchar(max)'), 1, 1, '')
    from TableA as A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2008. I have a table Customers customer_number int field1 varchar
I'm using SQL Server 2008. Say I create a temporary table like this one:
I'm using SQL Server 2008. I'm creating a DDL trigger like this: CREATE TRIGGER
Why does this script return a pair of nulls? I'm using SQL Server 2008,
Using SQL Server 2008, is there a way to allow inserts to a table
I am using SQL Server Reporting Services 2008 to create a report. A table
i'm using SQL Server 2008 and, in one of my tables, i implemented a
This is a question for a SQL expert. I'm using SQL Server 2008 R2
I am using SQL Server 2008 R2. I have imported 2 tables from excel
Using SQL Server 2008 (R2). I have two tables in different databases (with same

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.