The general structure of this type of update query in MSSQL follows a specific pattern.
- Start with the traditional structure of an update table in MSSQL.
- Put in the SET statements.
- Use the table being updated as the FROM table.
- Join the other tables you wish to pull values from.
- Make you WHERE statements to control which records are update and selected.
Here is a simple sample that updates fields of one table with values from two other tables:
UPDATE tblOne SET tblOne.clientName=tblTwo.firstName+' '+tblTwo.lastName,
tblOne.clientAddress=tblThree.streetAddress+' '+tblThree.city+', '+tblThree.prov+' '+tblThree.postal
FROM tblOne
INNER JOIN tblTwo ON tblOne.clientID=tblTwo.id
INNER JOIN tblThree ON tblTwo.id=tblThree.userID
WHERE tblOne.clientID=1
Easy Peasy, and it saved me a lot of programming code in cfml to transfer information from one table to an existing record of an other table.
No comments:
Post a Comment