Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert Multiple Rows Dynamically

Author  Topic 

sagarpbora
Starting Member

12 Posts

Posted - 2007-09-27 : 11:48:03
Hi All,

I am facing one problem currently while designing the database for my website.

I am having one table 'TABLE1' in which the values will be entered through the form. Users can enter multiple rows in it.

There is another table, 'TABLE2'.

What I want is I need to retrieve all the rows from TABLE1 for perticular session and then insert the row id for each row into the TABLE2, along with the table data.
All this should happen dynamically.

e.g.

TABLE1
======================================
ROW_ID(P.Key) | SESSION_ID | ROW DATA
======================================

TABLE2
===========================
ID | ROW_ID(F. Key) | DATA
===========================

Anybody having any idea about this?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-27 : 11:50:42
[code]Insert into Table2(Row_ID, Data)
Select Row_ID, Row_Data
From Table1
Where Session_ID = <some-value>[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

sagarpbora
Starting Member

12 Posts

Posted - 2007-09-27 : 12:03:23
Hi Harsh,

Thanks for your immediate response

Actually, here, the condition is bit different. I need to insert the rows in TABLE2 for the same ID which will be generated automatically.

Its like, customer is purchasing 10 items and in the end, the invoice is generated with the unique invoice id.
Go to Top of Page
   

- Advertisement -