Update record with data from another record in the same table 
Author Message
 Update record with data from another record in the same table


EXACTLY the same?

What do you get back from this?

-- raw data

 FROM    Contacts con


-- check for any spaces, unprintable characters, etc.


convert(varchar(255),con.contact_id) + '*'
 FROM    Contacts con


Cindy
http://www.***.com/

--------------------

| Newsgroups:
microsoft.public.sqlserver,microsoft.public.sqlserver.programming
| Subject: Update record with data from another record in the same table
| Date: 12 Jul 2001 13:19:05 -0700
| Organization: http://www.***.com/
| Lines: 46

| NNTP-Posting-Host: 64.19.39.80
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 994969146 21866 127.0.0.1 (12 Jul 2001
20:19:06 GMT)

| NNTP-Posting-Date: 12 Jul 2001 20:19:06 GMT
| Path:
cppssbbsa01.microsoft.com!news-out.cwix.com!newsfeed.cwix.com!news.maxwell.s
yr.edu!feeder.qis.net!sn-xit-02!supernews.com!postnews1.google.com!not-for-m
ail
| Xref: cppssbbsa01.microsoft.com
microsoft.public.sqlserver.programming:179427
| X-Tomcat-NG: microsoft.public.sqlserver
|
| In my SQL Server 2000 database I have a table called Contacts that
| stores addresses and such for a bunch of people and I need to write a
| stored procedure that copies the address of one contact to another.
|


| itself) but it doesn't work when they are different? I don't get any
| error messages, just "(0 row(s) affected)".
|
| UPDATE  Contacts
| SET     business_street = con.business_street,
|         business_city = con.business_city,
|         business_state = con.business_state,
|         business_zip = con.business_zip,
|         business_country = con.business_country,
|         business_phone1 = con.business_phone1,
|         business_phone2 = con.business_phone2,
|         business_fax = con.business_fax
| FROM    Contacts con


|
| I have verified that both IDs exist. I can do a SELECT * FROM Contacts

| the appropriate record back.
|
| Curiously, I have a similar query in a SQL Server 7.0 database that
| works just fine. In this case, the street address and phone numbers
| are copied from a table of companies but the e-mail address is copied
| from another record in the Contacts table. It looks like this:
|
| UPDATE  Contacts
| SET     city = com.city,
|         state = com.state,
|         zip = com.zip,
|         country = com.country,
|         phone1 = com.phone1,
|         phone2 = com.phone2,
|         fax = com.fax,
|         email = con.email
| FROM    Contacts con, Companies com



|
| What am I missing?
|



Sat, 07 Feb 2004 23:38:59 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Update record with data from another record in the same table

2. Update record with data from another record in the same table

3. UPDATE with multiple records per updated record?

4. Cached Updates QUESTION: Sorting table of updated and non-updated records

5. 1 table for many records or many tables with few records

6. Cannot add record to Visual Foxpro table after deleting all records in table

7. one table with lots of records or more table with less records

8. Fetch record into a plsql table (record.column_1 into table(index_1))

9. Trigger to update one table when records are added to another table

10. Update table for each record in another table

11. Table Lookup - Updating all records in table

12. grouping records , and updating the first record in each group


 
Powered by phpBB® Forum Software