Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Update Table
I have a field, Y, in table A that I need to update from table B,
matching on comman field X in both tables.

Table A has 10K+ records with field X in it (Field X multipul times).
Table B has only disctinct records in it based field X. Table B also has
a colume Y that I need to copy to table A's column Y.

So basically I want all of column Y's data in Table B copied to table
A's column Y.

One last point, I am using MS-Access to do the this.

I know this is a simple update command, but I can't seem to get it.

Can any one help me with this?

Thanks.
Mike
m charney at dunlap hospital dot net

Michael Charney

*** Sent via Developersdex http://www.droptable.com ***

Report this thread to moderator Post Follow-up to this message
Old Post
Nothing
03-28-06 02:29 PM


Re: Update Table
On Tue, 28 Mar 2006 14:50:33 GMT, Nothing wrote:

>I have a field, Y, in table A that I need to update from table B,
>matching on comman field X in both tables.
>
>Table A has 10K+ records with field X in it (Field X multipul times).
>Table B has only disctinct records in it based field X. Table B also has
>a colume Y that I need to copy to table A's column Y.
>
>So basically I want all of column Y's data in Table B copied to table
>A's column Y.
>
>One last point, I am using MS-Access to do the this.
>
>I know this is a simple update command, but I can't seem to get it.
>
>Can any one help me with this?

Hi Mike,

You're using Access, but you've posted the question to a SQL Server
newsgroup. I know that there are some differences in SQL syntax between
SQL Server and Access but I don't know what they are - if my suggestions
don't work, you should consider reposting the question to an Access
group.

Anyway, my first recommendation would be not to do this at all. If the Y
value in table A always has to be equal to the Y value in table B,
storing it in table A is redundant. Drop the column from table A and set
up a view (I believe Access calls a view a "query") instead:

SELECT     A.X, B.Y
FROM       A
INNER JOIN B
ON   B.X = A.X;

But if you really want to keep the redundant information, check if this
works:

UPDATE A
SET    Y = (SELECT B.Y
FROM   B
WHERE  B.X = A.X);

(Or, not recommended because it's non-standard syntax, less portable,
somewhat error-prone, but admittedly faster in some situations)

UPDATE     A
SET        Y = B.Y
FROM       A
INNER JOIN B
ON   B.X = A.X;


--
Hugo Kornelis, SQL Server MVP

Report this thread to moderator Post Follow-up to this message
Old Post
Hugo Kornelis
03-28-06 06:29 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 09:32 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006