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
 General SQL Server Forums
 New to SQL Server Programming
 Multiple SQL scripts...

Author  Topic 

fuzzyjon
Starting Member

15 Posts

Posted - 2008-02-13 : 04:59:55
Hello

I am using the following SQL which allows me to add "relationships" to records within our database:-

INSERT INTO organisation_links (organisation_number_1, organisation_number_2, relationship, amended_on, amended_by)
VALUES (2420, 19219, 'BRAN', '01/12/2007', 'Jon')

Basically, I would like to add the relationship of BRAN to multiple values of organisation_number_1 and am trying to find a way around copying the entire script many times and changing the e.g. 2420 number to other numbers.

The values for organisation_number_1 are not necessarily sequential.

The organisations_number_1 value can be found in the organisations table.

Any help would be much appreciated.

Many thanks

Jon

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-13 : 05:03:29
You mean something like this?

INSERT INTO organisation_links (organisation_number_1, organisation_number_2, relationship, amended_on, amended_by)
Select organisation_number_1, 19219, 'BRAN', '01/12/2007', 'Jon'
from organisations


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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-13 : 05:04:58
For answering this we need your business rules which determine what records from organisations table are to be related to BRAN. Can you post the rules and also table structure of organisations table?
Go to Top of Page

fuzzyjon
Starting Member

15 Posts

Posted - 2008-02-13 : 05:15:58
Hi Both,

Thanks for your help.

I think harsh_athalye is along the right lines of what I want to do.

organisation_number_1 equals, for example, the following values - 32005, 32006, 32027, 32034, 32041, 32042 etc...

So, should the script read something like this?

INSERT INTO organisation_links (organisation_number_1, organisation_number_2, relationship, amended_on, amended_by)
Select organisation_number_1, 19219, 'BRAN', '01/12/2007', 'Jon'
from organisations where organisation_number IN (32005, 32006, 32027, 32034, 32041, 32042)

Thanks for your continued help.

Jon


Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-13 : 05:22:35
Yes you can do that if there is no other way or pattern in filtering organisation_number_1 column.

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

- Advertisement -