Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update table

Author  Topic 

tsftsf
Starting Member

1 Post

Posted - 2008-03-02 : 06:02:11
Hi all,

I'm new to this forum.

I have the following tablename tcustomer IN EXCEL & I WANT TO WRITE A QUERY TO UPDATE MY TABLE IN SQL.

COl names

Old_Terms
Ledger
Fianacial
Entity_ID
Customer_Name
Region
Location_Code
newterm

All these colums are made in excel sheet. There are 3000 ROWS ALREADY WITH DATA.

I need to write a query to update the old credit terms with new credit terms for this table. But i have written the following query

update tcustomer set newterm="CASH" where Entity_id="ADAMS"

The two fields that change are newterm and entity_id

I have managed to merge these individual queries using mailmerge feature so that 3000 lines are generated which i can run in sql server and update my database.

This query will OVERRITE EVEN THE OLD CUSTOMER CREDIT TERMS AND REPLACE THEM WITH NEW CREDIT TERMS.

CAN ANYONE PLEASE HELP HOW TO WRITE A SUBQUERY WHICH WILL ONLY REPLACE THE NEW CREDIT TERMS THAT DON'T MATCH. THE MATCHING ROWS WOULD NOT BE ALTERED.

I WOULD APPRECIATE YOUR INPUT AS IM NOT A MASTER IN SQL .

REGARDS,
THADDEUS FERNANDES
UAE

thaddeus.fernandes@gmail.com

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-02 : 09:36:17
You had the conditions to the WHERE clause of the update, as one option..in this case only do the update where the new term does not equal the old term.


update customer
Set newterm = 'CASH'
where Entity_ID = 'ADAMS'
and newterm != oldterm




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page
   

- Advertisement -