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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:18:03+00:00 2026-06-14T19:18:03+00:00

Using SQL Server I have the following tables/ data CUS_VISIT Cus_ID Cus_Vis_ID 1 01

  • 0

Using SQL Server I have the following tables/ data

CUS_VISIT

Cus_ID    Cus_Vis_ID
1           01
1           02
2           01

and

CUS_EVENT

Cus_Event_ID    Cus_ID    Cus_Vis_ID
001               1            01
002               1            01

and

CUS_XREF

Cus_ID    Cus_Event_ID    Cus_Prt_ID    Cus_Seq_No
1            001               1           1
1            001               2           1

and

CUS_PRT

Cus_ID    Cus_Prt_ID    Prt_Cd
1            1            1A
1            2            2A

I have tried numerous queries but didn’t include them as i thought it would confuse things… most of them have used the xml path functionality but to no avail (i haven’t been trying pivot since there is a massive list of codes).

I am trying to get the following

SQL RESULTS

Cus_ID     Prt_Cd     Cus_Vis_ID
1           1A,2A        1

what I end up with is

SQL RESULTS

Cus_ID     Prt_Cd     Cus_Vis_ID
1           1A           1
1           2A           1

The tables are linked by …

CUS_VISIT.Cus_ID    = CUS_EVENT.Cus_ID 
CUS_VISIT.Cus_Vis_ID  = CUS_EVENT.Cus_Vis_ID
CUS_VISIT.Cus_ID = CUS_XREF.Cus_ID
CUS_EVENT.Cus_Event_ID = CUS_XREF.Cus_Event_ID    
CUS_XREF.Cus_Prt_ID = CUS_PRT.Cus_Prt_ID 
CUS_XREF.Cus_ID = CUS_PRT.Cus_ID 

I can almost get what I am after if I drop the CUS_XREF.Cus_Prt_ID = CUS_PRT.Cus_Prt_ID
join but then I get all of the part codes (Prt_Cd) for the customer not just the ones for that visit.

If it would help to see my unsuccessful queries or if I have left anything out sorry just let me know. Thanks for any help.

—

here is my subquery

stuff((
                  select ',' + B.prt_cd
                    from CUS_PRT B 
                    WHERE B.prt_cd = XREF.prt_cd  -- this is killing me
                    and XREF.cus_id=B.cus_id and 
                    -- some extra criteria i need but didn't think involved in my issue
                    B.prt_typ='1'  
                    and B.valid_entry='Y' and B.cur_entry_ind='Y'
                    for xml path('')),1,1,'')

here is my latest attempt. I added a new post because I didn’t realize an edit would move it to the top of the list again… I think i need another subquery somewhere but not sure where and how to tie it to the other two queries.

select distinct CUS_EVENT.cus_id, CUS_EVENT.cus_visit_id,
    (Select CUS_PRT.prt_cd + ',' AS [text()]
    From CUS_PRT, CUS_XREF
    where 
    CUS_EVENT.cus_id=XREF.cus_id
    and CUS_EVENT.cus_event_id = XREF.cus_event_id 
    and CUS_XREF.cus_id=CUS_PRT.cus_id 
    and CUS_XREF.cus_prt_id = CUS_PRT.cus_prt_id 
    and CUS_XREF.prt_seq_no ='1'
    order by CUS_PRT.prt_cd
    for XML PATH('')) [Codes]
from CUS_EVENT
  • 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-14T19:18:04+00:00Added an answer on June 14, 2026 at 7:18 pm

    i resolved this issue by creating a view that just associates the prt_cd with the event and then another view based on this one that combines (concatenates) all of the prt_cd s for one event… not sure why but was never able to find a way to do is all in one shot with one query.

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

Sidebar

Related Questions

I am using smarty php template and sql server I have the following tables
I'm using SQL Server 2005 and have the following T-SQL statement: DECLARE @MP VARCHAR(500)
We have an issue upgrading to SQL Server 2012. I am using the following
I am using SQL Server 2008 and I have the following SQL script: Select
i have the following table data in ms sql server table name category and
Using SQL Server 2008 (R2). I have two tables in different databases (with same
I have the following 2 tables defined in a SQL Server database: CREATE TABLE
I have the following table and data in SQL Server 2005: create table LogEntries
Using SQL Server 2005 I have a query that gets child records from bundles
[using SQL Server 2005] I have a table full of users, I want to

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.