Matching up the data with other table  
Author Message
lokee





PostPosted: Tue Oct 12 14:01:02 CDT 2004 Top

SQL Server Developer >> Matching up the data with other table

I have a Condition in Which I need to update the TableA with a new record if
the same
Address Does not Exists in the TableA as of TableB

If not Exists(Select Distinct B.Address From TABLEB B, Name A
where A.ID = â??24530â??
and B.Address <> A.Address
and B.County = 'Middlesex')
Begin
Insert into A.TableA
Select
B.Address,ID,mapname,eHouseName,
from TableA A, TableB B
Where A.Name not in (Select Distinct Address From TableB
Where County = 'Middlesex')
and County = 'Middlesex' â?? This is because otherwise it returns all the
Addresses
and A.ID = â??24530â??
group by B.Address,ID,mapname,eHouseName,
End

Please advice me with this Query
Thanks
samay

SQL Server78  
 
 
JohnBell





PostPosted: Tue Oct 12 14:01:02 CDT 2004 Top

SQL Server Developer >> Matching up the data with other table Hi

Posting DDL and Example data will help reduce any ambiguities may be in the
post http://www.aspfaq.com/etiquette.asp?id=5006. You may want to try
something like:

INSERT INTO TableA ( Address,ID,mapname,eHouseName )
SELECT Address,ID,mapname,eHouseName
FROM TableB B
WHERE NOT EXISTS ( SELECT * FROM TableA A WHERE A.ID = B.ID AND B.Address =
A.Address AND B.County = A.County AND A.County = 'Middlesex' AND A.ID =
â??24530â?? )


John




> I have a Condition in Which I need to update the TableA with a new record if
> the same
> Address Does not Exists in the TableA as of TableB
>
> If not Exists(Select Distinct B.Address From TABLEB B, Name A
> where A.ID = â??24530â??
> and B.Address <> A.Address
> and B.County = 'Middlesex')
> Begin
> Insert into A.TableA
> Select
> B.Address,ID,mapname,eHouseName,
> from TableA A, TableB B
> Where A.Name not in (Select Distinct Address From TableB
> Where County = 'Middlesex')
> and County = 'Middlesex' â?? This is because otherwise it returns all the
> Addresses
> and A.ID = â??24530â??
> group by B.Address,ID,mapname,eHouseName,
> End
>
> Please advice me with this Query
> Thanks
> samay
>