Re: Loop through records
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 12 May 2008 00:21:21 +0200
On Wed, 7 May 2008 19:56:00 -0700, Michael wrote:
Hello,
i have a table that has some informatio regarding an office building in it.
It also has the building managers information in it. I want to create two
new tables. One with just the building info, and one with just the managers
info. Now, I have created the two new tables. In the building table, I have
one column that has the ManagerID. So I have written a query that imports
all the building info into the new table. Here is my question. How can I
insert (one at a time I guess) the Managers into their new table while
updating the new ManagerID into the buildings table? If i was doing this
through something like C# I would just insert one row at a time, get the new
ID, the update the second table. But I do now know how to build that type of
look in SQL. Can someone help me?
Hi Michael,
Looping through the table and processing the rows one by one would
probably be the slowest possible option. And the one that needs the most
code. Of course, if this is a one time operation, then neither of these
arguments carry much weight :)
I'd like to help you, but you didn't provide enough information. I need
the following information:
* Table structure of all tables, both input and output (posted as CREATE
TABLE statements, including all constraints, indexes and properties;
irrelevant columns may be omitted though).
* Some well-chosen rows of sample data (posted as INSERT statements)
that illustrate all regular annd exceptional cases the code should be
able to handle.
* Expected results based on the sample data (can be posted in tabular
format, but please use a fixed-width font and spaces rather than the tab
character when laying out the table). In your case, the expected results
will not be output ona screen or a report, but two sets of data for
each of the two tables.
See www.aspfaq.com/5006 for more information on how to gather and post
this additional information.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.
- References:
- Loop through records
- From: Michael
- Loop through records
- Prev by Date: Extracting the table names to which a fied is related to
- Next by Date: Re: Extracting the table names to which a fied is related to
- Previous by thread: Loop through records
- Next by thread: Extracting the table names to which a fied is related to
- Index(es):
Relevant Pages
|
|