Solved

SQL Append/Update columns from one table to another?

Posted on 2010-09-07
7
269 Views
Last Modified: 2012-05-10
Hi there,

I have four columns of data in one table (frequency) within the same database that I wish to append/update into another table (company). I have tried an insert to statement but that didn't work due to the statement trying to create rows of which some of the fields cannot accept a null value.

I have revised my approach by using the attached code as means of trying to match the counter columns values to the same field in my company table. This code managed to loop through (incrementally) the company table and from this I would like to know if it would be possible for me to use possibly an IF statement to populate the company table with the fields from the frequency table when they are equal to each other, as both tables have a common realtion via the counter field?

Your help is much appreciated in advance
DECLARE @counter int
SET @counter = 0
UPDATE company
SET @counter = counter = @counter + 1

Open in new window

0
Comment
Question by:databarracks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 33615836
you want to update with a join?
http://www.experts-exchange.com/A_1517.html

not sure about your explanation(s) so far... a more concrete example might help ...
0
 

Author Comment

by:databarracks
ID: 33615993
Apologies for my rather confusing query. Yes I am trying to update existing rows and need the update to begin from the beginning of the row and work its way down. The below code from the link seems useful but I am not sure about the 'WHERE' clause? How would I write it to say that the 'counter' field in the frequency table equals the 'counter' field in the company table?


0
 

Author Comment

by:databarracks
ID: 33616050
To be honest all I am aiming to do is update the existing fields and rows in my company table with the values in the frequency table for the fields that are pervailent in both tables which are:

(contact_method, contact_frequency, contact_other, auto_email)
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33616059
can you please show sample data before and after the update?
0
 

Author Comment

by:databarracks
ID: 33616118
Hi,

Please find attached sample data. Kindly note that the (contact_method, contact_frequency, contact_other, auto_email) data values should be copied/appended/updated from the frequency table.
Sample-Data.xlsx
0
 

Author Comment

by:databarracks
ID: 33616195
I have found the solution from the link provided, thank you.
0
 

Author Closing Comment

by:databarracks
ID: 33616200
Helpful
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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…
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 …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

733 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