473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Table Overwrite

I wasn't able to figure out the vocab to search for this on usenet.
I'm sure it's an easy solution, but I have no experience with SQL
Server:

Situation:

tbl_CompanyData
is a 1735 x 20 table with a CompanyID key in the first column

tbl_MergedCompanyData
is a 1735 x 20 table imported from Excel. We found it much easier to
enter data into an Excel file.

Problem:

Keep the CompanyID field in tbl_CompanyData, but replace all the other
19 rows with data from tbl_MergedCompanyData, which contains all the
tbl_CompanyData PLUS new data that users filled in. At present, the
rows don't match up, but I suppose I could pre-sort the tables.
Preferrably, any solution would be smart enough to find CompanyID N in
tbl_MergedCompanyData and replace the data in the fifth column in
tbl_CompanyData where CompanyID is N with data from the fifth column
in tbl_MergedCompanyData.

Any thoughts would be appreciated. Please let me know if I can
clarify my problem.

Thank you,

Ryan
Jul 20 '05 #1
3 4901
UPDATE tbl_CompanyData
SET col5 =
(SELECT col5
FROM tbl_MergedCompanyData
WHERE companyid = tbl_CompanyData.companyid)

Remember, a table isn't a spreadsheet and columns have names not numbers :-)

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
Ritujoy (Ry************@gmail.com) writes:
I wasn't able to figure out the vocab to search for this on usenet.
I'm sure it's an easy solution, but I have no experience with SQL
Server:

Situation:

tbl_CompanyData
is a 1735 x 20 table with a CompanyID key in the first column

tbl_MergedCompanyData
is a 1735 x 20 table imported from Excel. We found it much easier to
enter data into an Excel file.

Problem:

Keep the CompanyID field in tbl_CompanyData, but replace all the other
19 rows with data from tbl_MergedCompanyData, which contains all the
tbl_CompanyData PLUS new data that users filled in. At present, the
rows don't match up, but I suppose I could pre-sort the tables.
UPDATE tbl_CompanyData
SET col1 = m.col1,
col2 = m.col2,
...
col19 = m.col19
FROM tbl_Companydata c
JOIN tbl_MergedCompanyData m ON c.CompanyID = m.CompanyID
Preferrably, any solution would be smart enough to find CompanyID N in
tbl_MergedCompanyData and replace the data in the fifth column in
tbl_CompanyData where CompanyID is N with data from the fifth column
in tbl_MergedCompanyData.


While you could add some code that reads the system tables and then
generates the command above, I am not sure that I would recommmend it.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
thanks gentlemen,


"David Portas" <RE****************************@acm.org> wrote in message news:<m4********************@giganews.com>...
UPDATE tbl_CompanyData
SET col5 =
(SELECT col5
FROM tbl_MergedCompanyData
WHERE companyid = tbl_CompanyData.companyid)

Remember, a table isn't a spreadsheet and columns have names not numbers :-)

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gord | last post by:
Hello, If you set the flag for an overwrite prompt using the 'Save' common dialog, how do you read the response when the user clicks the Yes or No in the 'overwrite' message box? Everything...
5
by: Jonas Asberg | last post by:
Hi, I got a new SQL Server database and are in the process of porting my Access databases to my new SQL Server. I have worked with Access and Oracle in the past but I am new to the SQL Server...
2
by: Colleyville Alan | last post by:
I have an app in which a ListBox is using a table called "Unique_Plans" as its RowSource. On another form, I create some changes to one table and then use a make-table query on the changed table...
6
by: deko | last post by:
Is there a way to set a custom property on Access tables and/or queries to prevent them from being overwritten by import wizards? Any Access database can be easily destroyed if a user mistakenly...
2
by: B-Dog | last post by:
Is there a way to make vb.net to overwrite the file when moving? Here is what I'm trying to do: If System.IO.File.Exists(dest) Then 'handle overwrite here If MessageBox.Show("Do you want...
3
by: Irfan | last post by:
hi, All I have a table in Access and I am using a storedProcedure (Make-Table query) to overwrite this table. It gives an error that 'Table Already Exists', which is true. But i want it to...
0
by: bluefalcon904 | last post by:
hi.. am such a newbie with SQL. im trying to update a table to overwrite a record . TABLE1 ORDERNUM NAME EVENT ORIGORDER 1 GEE ADD <NULL> 2 ...
5
by: DaveLock | last post by:
Hi, I have 3 tables of data created from different sources, each with the same 2 fields & I wanted to fill the 2nd field of another table with the data on condition. The condition is because...
1
by: arcingmad | last post by:
Hi I am using the following code in a button click event to run a query stored in a .mdb file from an external geographic program ArcGIS via a jet adodb connection I have the need to run an...
1
by: lionelm2007 | last post by:
Hi there, I have an update query that will insert a record from another table into an empty table. If I change ie a field in a record i like to overwrite that record in the table. This is not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.