Solved

Update Statement Using Info From Another Table

Posted on 2006-11-22
3
214 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now