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.
| 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.RateFrom tblA As A Inner Join tblT As T on T.ID = A.IDBut 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 |
 |
|
|
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 belowCREATE TRIGGER YourTriggerON tblT FOR INSERTASBEGINUpdate A Set A.sID = T.sID,A.strDesc = T.strDesc,A.strType = T.strType,A.Rate = T.RateFrom tblA As A Inner Join INSERTED As T on T.ID = A.IDEND 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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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? |
 |
|
|
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 |
 |
|
|
|
|
|