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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:51:09+00:00 2026-05-13T12:51:09+00:00

i have following 3 tables CREATE TABLE [dbo].[dspartner]( [dspartnerid] [bigint] IDENTITY(1,1) NOT NULL, [name]

  • 0

i have following 3 tables

CREATE TABLE [dbo].[dspartner](
[dspartnerid] [bigint] IDENTITY(1,1) NOT NULL,
[name] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[priority] [int] NULL)

CREATE TABLE [dbo].[hotels](
[hotelid] [int] PRIMARY KEY  IDENTITY(1,1) NOT NULL,
[name] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[DSPartnerid] [bigint] NULL,
)

CREATE TABLE [HotelSourceMap](
[hotelsourcemapid] [bigint] PRIMARY KEY  IDENTITY(1,1) NOT NULL,
[dspartnerid] [bigint] NOT NULL,
[hotelid] [bigint] NOT NULL,
    [dshotelid] bigint
)

situation is like this:

i want to table:dspartner contain details about datasource partner.
table:hotels contain details of hotels
table:HotelSourceMap contain record of hotels.hotelid, dsparnter.dspartnerid

new i want to update hotels table so that set hotels.dspartner = hotelsourcemap.dspartnerid
where
hotels.hotelid = hotelsourcemap.hotelid
and hotelsourcemap.dspartnerid = dspartner.dspartnerid (where dspartnerid’s priorirty is high)

Note:-priority contain int value and the max int value will be considerd as max priority. if two dspartner have same priority then get any one of them

sql server 2005

  • 1 1 Answer
  • 3 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-13T12:51:09+00:00Added an answer on May 13, 2026 at 12:51 pm

    Use:

    UPDATE HOTELS
       SET dspartners = (SELECT x.dspartnerid
                           FROM (SELECT hsm.dspartnerid,
                                        ROW_NUMBER() OVER(PARTITION BY hsm.hotelid 
                                                          ORDER BY p.priority, p.name DESC) AS rank
                                   FROM HOTELSOURCEMAP hsm
                                   JOIN DSPARTNER p ON p.dspartnerid = hsm.dspartnerid
                                  WHERE hsm.hotelid = hotelid) x
                          WHERE x.rank = 1)
    

    To make sure things are working properly, run:

    SELECT x.dspartnerid
      FROM (SELECT hsm.dspartnerid,
                   ROW_NUMBER() OVER(PARTITION BY hsm.hotelid 
                                     ORDER BY p.priority, p.name DESC) AS rank
              FROM HOTELSOURCEMAP hsm
              JOIN DSPARTNER p ON p.dspartnerid = hsm.dspartnerid
             WHERE hsm.hotelid = ?) x
     WHERE x.rank = 1
    

    Replace the ? with any hotelid of your choice.
    It will only return one dspartnerid value, even if there were more than one dspartnerid‘s with the same high priority.

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

Sidebar

Related Questions

I have the following table CREATE TABLE [dbo].[LogFiles_Warehouse]( [id] [int] IDENTITY(1,1) NOT NULL, [timestamp]
I have the following table: CREATE TABLE [dbo].[EntityAttributeRelship]( [IdNmb] [int] IDENTITY(1,1) NOT NULL, [EntityIdNmb]
I have the following table: CREATE TABLE [dbo].[PartsWork]( [parts_work_id] [int] IDENTITY(1,1) NOT NULL, [experiment_id]
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
I have the following table structures CREATE TABLE [dbo].[WorkItem]( [WorkItemId] [int] IDENTITY(1,1) NOT NULL,
I have the following table: CREATE TABLE [dbo].[Data] ( [Id] UNIQUEIDENTIFIER NOT NULL, [Data]
I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
I have a table Travelers : CREATE TABLE [dbo].[Travelers]( [TravelerId] [int] IDENTITY(1,1) NOT NULL,
I have following table schema - CREATE TABLE [dbo].[TEST_TABLE] ( [TEST_TABLE_ID] [int] IDENTITY(1,1) NOT
I have the following tables: CREATE TABLE title ( booktitle VARCHAR( 60 ), title_id

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.