Solved

SQL Append/Update columns from one table to another?

Posted on 2010-09-07
7
267 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
  • 5
  • 2
7 Comments
 
LVL 142

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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 142

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
script to send html report 3 29
I Need a T-SQL Query (Union or Intersect, or...?) 6 38
VB.net and sql server 4 33
SSRS Enable Remote Errors 4 21
I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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…

815 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

8 Experts available now in Live!

Get 1:1 Help Now