Solved

Update Statement Using Info From Another Table

Posted on 2006-11-22
3
227 Views
Last Modified: 2008-03-06
I have 4 colomns in table1 (table1.column1, table1.column2, table1.column3,  table1.column4) that I want overwritten by the same 4 columns in table2 (table2.column1, table2.column2, table3.column3,  table2.column4).

The 4 columns need to be changed only when the following criteria is met:

WHERE table1.campaign = table2.campaign
and table1.[ad group] = table2.[ad group]
and table1.[report type] = table2.[report type]
and table1.campaign = table2.campaign
and table1.[adgroup status] = table2.[adgroup status]
and table1.[creative status] = table2.[creative status]
and table1.[campaign status] = table2.[creative status]

How do i accomplish this?

thanks
 
0
Comment
Question by:restockit
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 500 total points
ID: 18000277
Hi restockit,

try this:

UPDATE table1 t1
set
    t1.column1 = t2.column1,
    t1.column2 = t2.column2,
    t1.column3 = t2.column3,
    t1.column4 = t2.column4
FROM
    table2 t2
WHERE table1.campaign = table2.campaign
and table1.[ad group] = table2.[ad group]
and table1.[report type] = table2.[report type]
and table1.campaign = table2.campaign
and table1.[adgroup status] = table2.[adgroup status]
and table1.[creative status] = table2.[creative status]
and table1.[campaign status] = table2.[creative status]


Cheers,
Hillwaaa
0
 

Author Comment

by:restockit
ID: 18000384
thanks!!
0
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18000391
No worries!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question