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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:21:41+00:00 2026-05-20T16:21:41+00:00

I have 3 tables: Accounts (fields used: ID varchar(20) and Name varchar(50)) OpttyPartner( fields

  • 0

I have 3 tables:

  1. Accounts (fields used: ID varchar(20) and Name varchar(50))

  2. OpttyPartner( fields used : ID15 varchar(20) , ACCOUNTTOID varchar(20)

  3. Final2([Opportunity ID] varchar(20), Partner varchar(400)

I need to update Partner field of every record for final2 with name from accounts table.
Final2 is related to OpptyPartner with {opportunity ID] and ID15
Accounts is related with OpptyPartner with ID and ACCOUNTTOID

If there are more than one accounttoid for same Opportunity ID then the names should be appended and seperated with a ‘;’

For example:

 Final2

 ID       Partner
 1       


 OpptyPartner
 ID15                ACCOUNTTOID
  1                   A1
  1                   A2

 Accounts
  ID                 Name
   A1                 ABC com
   A2                 EFG com

The output in Partner should be ‘ABC com;EFG com’

How can this be achieved? Cursors ?

UPDATE:

    ;With partners as
(select * from Accounts inner join OpptyPartner on 
Accounts.ID COLLATE Latin1_General_CS_AS=OpptyPartner.[ACCOUNTTOID] COLLATE Latin1_General_CS_AS
inner join Final2 on Final2.[Opportunity ID] = OpptyPartner.ID15)
Update Final2 set Partner = p.Names from 
Final2 inner join
(select [Opportunity ID] , LEFT(Names, len(Names)-1) as Names from 
(SELECT j.[Opportunity ID] ,

  ( SELECT cast(p1.NAME  as varchar(10)) + ';'

       FROM partners p1

      WHERE p1.[Opportunity ID] = j.[Opportunity ID]

      ORDER BY NAME

        FOR XML PATH('') ) AS Names
  FROM partners j
  GROUP BY [Opportunity ID] )A
  ) p on Final2.[Opportunity ID] = p.[Opportunity ID]
  • 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-20T16:21:42+00:00Added an answer on May 20, 2026 at 4:21 pm

    I think this might be of use:

        ;With partners as
    (select [Opportunity ID], Name from accounts inner join OpttyPartner on 
    accounts.id=OpttyPartner.[ACCOUNTTOID]
    inner join final2 on final2.[Opportunity ID] = OpttyPartner.id15)
    Update final2 set partner = p.names from 
    final2 inner join
    (select [Opportunity ID] , LEFT(Names, len(Names)-1) as Names from 
    (SELECT j.[Opportunity ID] ,
    
          ( SELECT cast(p1.Name  as varchar(10)) + ';'
    
               FROM partners p1
    
              WHERE p1.[Opportunity ID] = j.[Opportunity ID]
    
              ORDER BY Name
    
                FOR XML PATH('') ) AS Names
          FROM partners j
          GROUP BY [Opportunity ID] )A
    ) p on final2.[Opportunity ID] = p.[Opportunity ID]
    

    Try using this (add collation where necessary) if you have multiple records in opptyPartner with same ID15 and ACCOUNTTOID :

        ;With partners as
    (select [Opportunity ID], Name from accounts inner join (select distinct [ID15]
          ,[ACCOUNTTOID] from OpttyPartner) OpttyPartner on 
    accounts.id=OpttyPartner.[ACCOUNTTOID]
    inner join final2 on final2.[Opportunity ID] = OpttyPartner.id15)
    Update final2 set partner = p.names from 
    final2 inner join
    (select [Opportunity ID] , LEFT(Names, len(Names)-1) as Names from 
    (SELECT j.[Opportunity ID] ,
    
          ( SELECT cast(p1.Name  as varchar(10)) + ';'
    
               FROM partners p1
    
              WHERE p1.[Opportunity ID] = j.[Opportunity ID]
    
              ORDER BY Name
    
                FOR XML PATH('') ) AS Names
          FROM partners j
          GROUP BY [Opportunity ID] )A
    ) p on final2.[Opportunity ID] = p.[Opportunity ID]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id,
I'm using MySQL I have three tables: accounts { account_id, username } account_ips {
I have tables contracts and users and i need to show contracts sorted by
I have two tables: Events (ID, Name, Time, Recorder) Video (ID, StartTime, EndTime, Recorder,
I have the following setup: Tasks, Accounts and Groups tables. Tasks can be assigned
I'm using mysql/php/apache . I have the following situation: 2 tables where I need
I have two tables in mySQL, notably accounts and subscriber_data. I want to use
I have following tables : users accounts ( user has_one account ) pictures (
I have 2 MySQL tables, 'scheduled_time' and 'appointments' 'scheduled_time' has 2 DateTime fields, 'start'
I have a MySQL table called accounts . Within this table is a field

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.