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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:51:17+00:00 2026-06-13T01:51:17+00:00

I have two tables: Table1 : RulesVectorID(nullable, primary),Weight,IsDeleted Table2 : RulesVectorID(forigen) , Weight,IsDeleted, NumberOfOffers,

  • 0

I have two tables:

Table1:

RulesVectorID(nullable, primary),Weight,IsDeleted

Table2:

RulesVectorID(forigen) , Weight,IsDeleted, NumberOfOffers, other fields...

I want to do tow things:

  1. assign Id to all rows in table1 where RulesVectorID ==null

    I tried this:

    UPDATE myTable1
    SET RulesVectorID = SELECT MAX(RulesVectorID) + 1 FROM myTable1,
    WHERE RulesVectorID IS NULL
    
  2. To rows added in step (1) I want to copy their Weight, IsDeleted columns and add 1 to their NumberOfOffers

    I tried this:

    INSERT INTO myTable2 (Weight, IsDeleted, NumberOfOffers, RulesVectorID) 
    VALUES (
      SELECT Weight, IsDeleted, 1, RulesVectorID 
      FROM myTable1 
      WHERE myTable1.RulesVectorID NOT IN (SELECT RulesVectorID FROM myTable2))
    

Is there any cleaner way to do it?

  • 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-13T01:51:18+00:00Added an answer on June 13, 2026 at 1:51 am
    ;with t as (
    select *, rn=row_number() over (order by weight)
    from mytable1
    where RulesVectorID is null)
    update t set RulesVectorID = rn + isnull((Select max(RulesVectorID) from myTable1),0);
    

    Second query looks ok once you drop the values()

    insert into myTable2 (Weight,IsDeleted,NumberOfOffers,RulesVectorID) 
    select Weight,IsDeleted,1,RulesVectorID 
    from myTable1 
    where myTable1.RulesVectorID not in (select RulesVectorID from myTable2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables as: table1 with fields c1 and dt (nullable); table2 with
I have two tables: Table1: id attr1 fk1(Table2) fk2(Table2) Table2: id name I want
I have two tables Table1 and Table2. There are 10 fields in Table1 and
I have two tables (Table1 and Table2.) I want to delete all rows in
I have two tables (Table1 and Table2) with the same primary keys, lets say
I have two tables table1 with fields f1 , f2 and table2 with fields
i have two tables Table1 and Table2. Where table1 column primary key is referred
I have two tables - table1 and table2 table1 has 14 columns and table2
I have two tables table1 and table2 each having a column named email along
i have two tables table1 fields fid,fname,fage a ,abc ,20 b ,bcv ,21 c

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.