> This will fail with an error if name isn't unique in table2.
and returned 53 records. Once I clean these up, my update should work.
manually deleting them. Do you have any suggestions as to what options I
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message
news:uTKijbmYGHA.4920@TK2MSFTNGP02.phx.gbl...
> "Matt Williamson" <ih8spam@spamsux.org> wrote in message
> news:O6cvpMmYGHA.1204@TK2MSFTNGP04.phx.gbl...
>> I'm having way more trouble with this than I should be. There are no
>> constraints on either table. This is just a temporary data dump to export
>> to a file.
>>
>> I just want to update a field in one table (AcctNum) with the same field
>> from another table using a common column (Name).
>>
>> ex.
>>
>> Table 1
>> ActNum, Name
>>
>> Table 2
>> Name, Address, Phone
>>
>> I want the output to be
>>
>> Table 2 (or table 3, I don't care)
>> ActNum, Name, Address, Phone
>>
>> Do I need an Insert or Update query for this? I've tried both with no
>> luck. I've simplified this tremendously, but if someone can show me the
>> best way to acheive my sample, I can take it from there.
>>
>
> A guess:
>
> UPDATE table1
> SET acctnum =
> (SELECT acctnum
> FROM table2
> WHERE table2.name = table1.name) ;
>
> This will fail with an error if name isn't unique in table2. What do you
> want to do if there is more than one row (and therefore maybe more than
> one acctnum) for a given name?
>
> --
> David Portas, SQL Server MVP
>
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
>
> SQL Server Books Online:
>
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
>