T-sql Update Query

ukerandi
ukerandi used Ask the Experts™
on
Hi I used following t-SQL command to Update name in the TEST_DeliveryAddress  table ,need to take CustAddTest Table name.
But no errors and showing successfully run the query but NOT updating the TEST_DeliveryAddress  Table name field.Any idea what is wrong
Thanks
BEGIN TRY  
  BEGIN TRANSACTION
  UPDATE
    TEST_DeliveryAddress
SET
   name = OT.name
 
FROM
    CustAddTest T
INNER JOIN
    TEST_DeliveryAddress OT
ON
    T.[Customer] = OT. [Cust_Number] AND T.cust_seq=0
    COMMIT
END TRY
BEGIN CATCH

    IF @@TRANCOUNT > 0
        ROLLBACK
END CATCH
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior .Net Developer
Commented:
If you're taking the custaddtest then that would be:


UPDATE
    OT
SET
   OT.name = T.name
 
FROM
    CustAddTest T
INNER JOIN
    TEST_DeliveryAddress OT
ON
    T.[Customer] = OT. [Cust_Number] AND T.cust_seq=0

Open in new window


ensure you're getting that by running this:

select
   OT.name oldName, T.name newName
 FROM
    CustAddTest T
INNER JOIN
    TEST_DeliveryAddress OT
ON
    T.[Customer] = OT. [Cust_Number] AND T.cust_seq=0

Open in new window

Brian CroweDatabase Administrator
Top Expert 2005

Commented:
You are updating the TEST_DeliveryAddress.name column with the TEST_DeliveryAddress.name column.  There isn't going to be any  change.
Jagdish DevakuSr DB Architect
Commented:
BEGIN TRY  
  BEGIN TRANSACTION 
  UPDATE
    OT
SET
   OT.name = T.name
 
FROM
    CustAddTest T
INNER JOIN
    TEST_DeliveryAddress OT
ON
    T.[Customer] = OT. [Cust_Number] AND T.cust_seq=0
    COMMIT
END TRY
BEGIN CATCH

    IF @@TRANCOUNT > 0
        ROLLBACK
END CATCH

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial