Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 5123

Updating SQL DB fields with multiple target records

$
0
0

Hi,

I am trying to multiple update records in Table B from a single record in Table A.  To identify the records that need to be updated I used this:

Select

Table1.cfirstnameas'Table 1 First',Table1.clastnameas'Table 1 Last',Table1.ifamilyid,CR.icontactid,CR.lLiveswithStudent,


Table2.cfirstnameas'Table 2 First',Table2.cLastNameas'Table 2 Last',Table2.ilocationidas'Table 2 Location',Table1.iLocationIDas'Table 1 Location'


fromTable1

JoinTable3CRonTable1.istudentid=CR.istudentid

JoinTable2onCR.icontactid=Table2.iContactID


whereCR.lLivesWithStudent=1andTable1.ifamilyid>0andTable1.ilocationid<>Table2.iLocationIDandTable1.lCurrent=1

I need to update the ilocationid from Table 1 to all Table 2 records related to Table 1but there is no direct relation from Table 1 to Table 2.  I needed Table 3 to make the connection from Table 1 to 2

Thank you


Viewing all articles
Browse latest Browse all 5123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>