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
 General SQL Server Forums
 New to SQL Server Programming
 Update statement

Author  Topic 

ra_pa_ta
Starting Member

13 Posts

Posted - 2011-09-29 : 10:49:33
Here is my update statement
Update A Set A.sID = T.sID,A.strDesc = T.strDesc,A.strType = T.strType,
A.Rate = T.Rate
From tblA As A Inner Join tblT As T on T.ID = A.ID

But I dont want to update all the records in the table A instead only when a new records comes in table T . is there a better way to write my Update statement ?

theboyholty
Posting Yak Master

226 Posts

Posted - 2011-09-29 : 11:15:16
You would first need to establish how a record is defined as New from table T. Is there some kind of DATETIME column you could refer to?

---------------------------------------------------------------------------------
http://www.mannyroadend.co.uk A Bury FC supporters website and forum
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-29 : 12:12:26
if you need to do it only for new insertion you've to either implement it using an insert trigger like below

CREATE TRIGGER YourTrigger
ON tblT
FOR INSERT
AS
BEGIN
Update A Set A.sID = T.sID,
A.strDesc = T.strDesc,
A.strType = T.strType,
A.Rate = T.Rate
From tblA As A
Inner Join INSERTED As T
on T.ID = A.ID
END


another way is to handle this in insert procedure itself by means of OUTPUT clause. But in this case, please keep in mind that any adnoc inserts without using the insert proc will ignore this processing altogether.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-09-29 : 12:29:35
quote:
Originally posted by ra_pa_ta

<snip>But I dont want to update all the records in the table A instead only when a new records comes in table T . is there a better way to write my Update statement ?

I don't think you can update a new row becauase it wouldn't exist if it's new, would it? Or do you want to update changed rows?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-29 : 14:33:13
Please do not post duplicate questions in multiple forums. I have deleted your duplicate post
Go to Top of Page
   

- Advertisement -