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 2000 Forums
 SQL Server Development (2000)
 After Insert Into of one row, create 3 extra rows

Author  Topic 

hueby
Posting Yak Master

127 Posts

Posted - 2006-03-23 : 18:29:03
Hi all,

I'll try to explain this the best I can. Hopefully the way I'm attempting to do this makes some sense, and is in the right direction.

I will have one row of data including these columns, for example, item_code, vendor, sortnumber. They are all primary keys.

From this row, I need to create 3 extra rows with variation in the sortnumber.

For example, I start off with:
item_code, vendor, sortnumber
BLAH, ABC, 1


Then, I need to get this from some code, etc.

item_code, vendor, sortnumber
BLAH, ABC, 1
BLAH, ABC, 2
BLAH, ABC, 3
BLAH, ABC, 4


So... can I get some suggestions, help, etc??

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-23 : 18:49:20
if you are doing the insert via stored procedure, you can perform the 3 additional rows of insert there.

You can also use insert trigger to do this



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-24 : 05:06:09
Also, why do you want to do this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

hueby
Posting Yak Master

127 Posts

Posted - 2006-03-24 : 09:25:49
Hi all,

Thanks for the info. I did not realize I could do multiple inserts in a SP like this. Cool...

I have to do this, because of our current accounting system. I'm doing some custom data dumping, and their database requires some weird things......
Go to Top of Page

hueby
Posting Yak Master

127 Posts

Posted - 2006-04-07 : 10:34:48
Okay, so I know what I want to do now.. but how do I get in a "multiple insert"?

INSERT into test1..IM_super_xref_mc(company_code, sort_type, key_1, key_2, key_3, item_code)
select company_code, '1', item_category, vendor_code_list1, vendor_part_number, item_code from test1..im_item_master_mc

INSERT into test1..IM_super_xref_mc(company_code, sort_type, key_1, key_2, key_3, item_code)
select company_code, '2', ' ', vendor_code_list1, vendor_part_number, item_code from test1..im_item_master_mc

INSERT into test1..IM_super_xref_mc(company_code, sort_type, key_1, key_2, key_3, item_code)
select company_code, '3', ' ', ' ', vendor_part_number, item_code from test1..im_item_master_mc

INSERT into test1..IM_super_xref_mc(company_code, sort_type, key_1, key_2, key_3, item_code)
select company_code, '4', ' ', ' ', ' ', item_code from test1..im_item_master_mc
Go to Top of Page

hueby
Posting Yak Master

127 Posts

Posted - 2006-04-07 : 11:14:51
Disregard this.. I found a solution.

INSERT into test1..IM_super_xref_mc(company_code, sort_type, key_1, key_2, key_3, item_code)
select company_code, '1', item_category, vendor_code_list1, vendor_part_number, item_code
from test1..im_item_master_mc
union all
select company_code, '2', ' ', vendor_code_list1, vendor_part_number, item_code
from test1..im_item_master_mc
union all
select company_code, '3', ' ', ' ', vendor_part_number, item_code
from test1..im_item_master_mc
union all
select company_code, '4', ' ', ' ', ' ', item_code
from test1..im_item_master_mc
Go to Top of Page
   

- Advertisement -