dbTalk Databases Forums  

Other way than SP?

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss Other way than SP? in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paulo
 
Posts: n/a

Default Other way than SP? - 08-28-2009 , 01:57 PM






The SP opens a cursor and loop a product table on a DB and generates the
records that was read to other 3 tables on other DB...

@iID=0
Loop "Select * from DB.Product"
@iID = @iID + 1
Insert into otherDB.Product(ID,Description,otherfields...) values select
@iID, description, ..., ...
Insert into otherDB.ProductStock(ID,QttValue,otherfields...) values
select @iID, description, ..., ...
Insert into otherDB.AnotherTable(ID,otherfields...) values select @iID,
etc, ..., ...
Next

I need the same ID for the record that will be inserted on the others
tables...

Is there other way instead using SP?

Thanks
MS SQL 2000

Reply With Quote
  #2  
Old   
John Bell
 
Posts: n/a

Default Re: Other way than SP? - 08-28-2009 , 02:53 PM






"Paulo" <eris_paulo (AT) terra (DOT) com.br> wrote

Quote:
The SP opens a cursor and loop a product table on a DB and generates the
records that was read to other 3 tables on other DB...

@iID=0
Loop "Select * from DB.Product"
@iID = @iID + 1
Insert into otherDB.Product(ID,Description,otherfields...) values select
@iID, description, ..., ...
Insert into otherDB.ProductStock(ID,QttValue,otherfields...) values
select @iID, description, ..., ...
Insert into otherDB.AnotherTable(ID,otherfields...) values select @iID,
etc, ..., ...
Next

I need the same ID for the record that will be inserted on the others
tables...

Is there other way instead using SP?

Thanks
MS SQL 2000

Hi

If you insert everything into a temporary table, possibly allocating the id
through an identity. You can then have a know set of ids and you wouldn't
need to loop just use insert...select. Alternatively if you have all the
information in the first table you could try a trigger and use the inserted
table.

John

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.