Let's keep it short and sweet
I want to do this (I've failed numerous times now, and one attempt even updated the Row with blanks):
UPDATE Database2.Table1
SET (Database2.Table1.Column1, Database2.Table1.Column2, Database2.Table1.Column3)
VALUES
(Database1.Table1.Column1, Database1.Table1.Column2, Database1.Table1.Column3)
WHERE Database2.Table1.Column1 = Database1.Table1.Column1
These two already contain the same value, but the other 2 columns do not, and that is what I wish to change with this query..
Here's how each table look:
Database1.Table1
[id]
[name]
[applicationdate]
[startdate]
[shortdescription]
[longdescription]
[displayimg]
[contact]
[website]
[created]
[urlbase]
[site]
[keywords]
[type]
[location]
Database2.Table1
[id]
[name]
[applicationdate]
[startdate]
[content]
[keywords]
[customerid]
[urlbase]
[shortdescription]
[meta]
[type]
[site]
[searchurlbase]
[lang]
[educationlength]
[locations]
[educationwebsite]
[contact]
[tags]
[educationtypes]
[created]
[category]
Any help is greatly appreciated, thank you for your time :)
Sorry if it doesn't make any sense, I easily get confused when trying to explain problems I'm having
Using SQL Server Management StudioOpen the table with columns you want to copy and the one you want to copy into by right-clicking the tables, and then clicking Design. Click the tab for the table with the columns you want to copy and select those columns. From the Edit menu, click Copy.
Select and right-click on the Source Database, go to Tasks > Export Data. Import/Export Wizard will be opened and click on Next to proceed. Enter the data source, server name and select the authentication method and the source database. Click on Next.
If you want to copy the data of one SQL table into another SQL table in the same SQL server, then it is possible by using the SELECT INTO statement in SQL. The SELECT INTO statement in Structured Query Language copies the content from one existing table into the new table.
UPDATE dest
SET column2 = src.column2,
column3 = src.column3
FROM Database2.dbo.Table1 AS dest
INNER JOIN Database1.dbo.Table1 AS src
ON dest.column1 = src.column1;
Given your collate problem, you can specify collate in the equality operation. Having no idea which side is giving the problem, and assuming you don't care about case sensitivity:
UPDATE dest
SET column2 = src.column2,
column3 = src.column3
FROM Database2.dbo.Table1 AS dest
INNER JOIN Database1.dbo.Table1 AS src
ON dest.column1 COLLATE Finnish_Swedish_CI_AS
= src.column1 COLLATE Finnish_Swedish_CI_AS;
If you care about case sensitivity, then change both clauses to the _CS_AS_
one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With