MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Insert Multiple Rows

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
psridhar
Beginner


Joined: 16 May 2004
Posts: 68
Topics: 26

PostPosted: Sun May 16, 2004 11:24 am    Post subject: Insert Multiple Rows Reply with quote

Hi,

Table 1:
Code:

-------------------------------------------
|       |    Authorised    |            |
| Id    |   for Department |  Date      |
--------------------------------------- |---
|AAA    |    DEP1          | 2004-01-10 |
|AAA    |    DEP2          | 2004-01-12 |
|AAA    |    DEP3          | 2004-02-05 |
|AAA    |    DEP4          | 2003-10-03 |
|BBB    |    DEP2          | 2004-05-01 |
--------------------------------------------

My requirement is I have to give authority to BBB (Insert rows with Id as BBB) for all the derartments for which AAA is having authority. Date must be current date.

Expected Insertions
Code:

-------------------------------------------
|       |    Authorised    |            |
| Id    |   for Department |  Date      |
----------------------------------------|
|BBB    |    DEP1          | 2004-05-16 |
|BBB    |    DEP3          | 2004-05-16 |
|BBB    |    DEP4          | 2004-05-16 |
-----------------------------------------

Can anybody suggest me an SQL which satisfies my requirement.

The only way I see is fetch all the rows from table with Id = AAA. For each department, Check for a row in the table with Id = BBB. If row is not there, insert it. But for this I need a program. But what I need is a single SQL (with out any program......!)

thanks in advance
Sridhar
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Sun May 16, 2004 12:03 pm    Post subject: Reply with quote

Sridhar,

Try this sql

Code:

INSERT INTO TABLE (SELECT CHAR('BBB'),AUTH_DEPT,CURRENT DATE
                   FROM TABLE
                  WHERE AUTH_DEPT IN (SELECT AUTH_DEPT FROM TABLE
                                       WHERE ID = 'AAA')               
                    AND AUTH_DEPT NOT IN (SELECT AUTH_DEPT FROM TABLE
                                            WHERE ID = 'BBB'))
;             


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
psridhar
Beginner


Joined: 16 May 2004
Posts: 68
Topics: 26

PostPosted: Mon May 17, 2004 10:08 am    Post subject: Reply with quote

Thanks alot Kosulu

Sridhar
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group