PDA

View Full Version : Develop query to transfer data



mubi_masti
10-19-2011, 12:34 AM
Hello

Can any one help me in developing a query

I have three tables, tblA, tblB, tblC

Tbl A has two fields, std and camp
While tbl B also has same to field ( it is temporary table)
tblC has one field camp

tbl A and and tbl C are linked with 1 to many relationship

I want to transfer data from tblB to tblA where

(tblB.std is not in tblA.std) but (tblB.camp of same std = tblC.camp)

After that

Delete all entries in tblB where


(tblB.std = tblA.std) and (tblB.camp = tblA.camp)

mohanvijay
10-19-2011, 02:05 AM
try this



'for append

INSERT INTO tblA (std,camp) SELECT tblB.std,tblB.camp FROM tblB,tblC WHERE tblB.std IN (SELECT t1.std FROM tblB as t1 LEFT OUTER JOIN tblA as t2 ON t1.std=t2.std WHERE t2.std IS NULL) AND tblB.camp=tblC.camp

'for delete

DELETE FROM tblB WHERE tblB.std IN (SELECT tblA.std FROM tblA WHERE tblA.std=tblB.std) AND tblB.camp IN (SELECT tblC.camp FROM tblC WHERE tblC.camp=tblB.camp)

mubi_masti
10-19-2011, 03:12 AM
great !!!!

Mohanvijay, you have solve my big problem, thanks a lot, both queries are working fine