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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:22:51+00:00 2026-05-18T02:22:51+00:00

I have a status table, and another table containing additional data. My object IDs

  • 0

I have a status table, and another table containing additional data. My object IDs are the PK in the status table, so I need to insert those into the additional data table for each new row.

I need to insert a new row into my statusTable for each new listing, containing just constants.

declare @temp TABLE(listingID int)

insert into statusTable(status, date)
  output Inserted.listingID into @temp
select 1, getdate()
from anotherImportedTable

This gets me enough new listing IDs to use.

I now need to insert the actual listing data into another table, and map each row to one of those listingIDs –

insert into listingExtraData(listingID, data)
select t.listingID, a.data
from @temp t, anotherImportedTable a

Now this obviously doesn’t work, because otherDataTable and the IDs in @temp are unrelated… so I get far too many rows inserted.

How can I insert each row from anotherImportedTable into listingExtraData along with a unique newly created listingID? could I possibly trigger some more sql at the point I do the output in the first block of sql?

edit: thanks for the input so far, here’s what the tables look like:

anotherImportedTable:

data

statusTable:

listingID (pk), status, date

listingExtraData:

data, listingID

You see that I only want to create one entry into statusTable per row in anotherImportedTable, then put one listingID with a row from anotherImportedTable into listingExtraData… I’m thinking that I might have to resort to a cursor perhaps?

  • 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-18T02:22:51+00:00Added an answer on May 18, 2026 at 2:22 am

    Ok, here’s how you can do it (if I’m right about what you actually want to do):

    insert into listingExtraData(listingID, data)
    select q1.listingID, q2.data
    from 
       (select ListingID, ROW_NUMBER() OVER (order by ListingID) as rn from @temp t) as q1
       inner join (select data, ROW_NUMBER() over (order by data) as rn from anotherImportedTable) q2 on q1.rn = q2.rn
    

    In case you matching logic differs you will need to change sorting of anotherImportedTable. In case your match order can not be achieved by ordering anotherImportTable [in one way or another] then you’re out of luck.

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

Sidebar

Related Questions

I'm stuck with retrieving data from a MySQL-database in an efficient way. I have
I have two tables. One table is meant to serve as a transaction history
I currently have a table that is listed as follows: projects = Project.find(:all, :conditions
I have designed a stored procedure usign Sql Server 2005 below to compare 3
I encountered an error when doing the following retrieval: class status(models.Model): pid = models.IntegerField()
We are developing an inventory tracking system. Basically we've got an order table in
I want to create a procedure that will A) check to see if TicketNumberInput
I'm fighting with creation of several forms in MS Access 2007. I accomplished the
I've just come across a strange behaviour in Oracle where I would expect ORA-00918

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.