| Author |
Topic |
|
Lukesb
Starting Member
6 Posts |
Posted - 2009-03-09 : 10:59:39
|
| Hi EveryoneHope I got this posted in right section...I am trying to create a trigger in SQL server management studio...I have used the followingcreate trigger EditDescon dbo.ILines after insertasbeginif (select PG from inserted) =20 update inserted set BopDes = 'TESTESTESTESTEST'endgoI can't run it to create the trigger as table inserted doesn't exist...How can I get this saved so that it runs when records are inserted on the table dbo.ILines..?Thanks very muchLuke |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-03-09 : 11:09:08
|
| You can't update the virtual tables [inserted] and [deleted]. If you want to overwrite the new values you need to update the target table [ILines] - INNER JOIN to [inserted] so that you only update the new rows.Be One with the OptimizerTG |
 |
|
|
Lukesb
Starting Member
6 Posts |
Posted - 2009-03-09 : 11:20:57
|
| Hi TGThanks for that. It makes perfect sense now you've explained it...I will keep on at it now...If I get it right, do I just execute to save it..?CheersLuke |
 |
|
|
Lukesb
Starting Member
6 Posts |
Posted - 2009-03-09 : 11:43:30
|
| I now have the followingcreate trigger EditDescon dbo.ILines for insertasif (select PG from inserted) =20begin update dbo.ILines set BopDes = 'TESTESTESTESTEST' where dbo.ILines.[DateTime] = (select datetime from inserted)endgoBut get the following errorMsg 8197, Level 16, State 4, Procedure EditDesc, Line 1The object 'dbo.ILines' does not exist or is invalid for this operation.Any ideas on this..?ThanksLuke |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-03-09 : 12:13:46
|
| [code]Create Trigger EditDescon dbo.ILines for insertasIF Exists (Select 1 from inserted Where PG = 20)begin update IL set IL.BopDes = 'TESTESTESTESTEST' from dbo.ILines IL Inner join Inserted I ON I.[datetime] = IL.[datetime] endgo[/code] |
 |
|
|
Lukesb
Starting Member
6 Posts |
Posted - 2009-03-09 : 12:26:13
|
| Hey sodeepThanks for reply, but I am still getting an error. This time it saysMsg 2812, Level 16, State 62, Line 1Could not find stored procedure 'dbo.ILines'.Thanks again..!Luke |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-03-09 : 14:03:12
|
| Do you have table named dbo.ILines? |
 |
|
|
Lukesb
Starting Member
6 Posts |
Posted - 2009-03-09 : 15:05:46
|
| Yes, I do... |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-03-09 : 15:36:43
|
| The trigger code is fine. Do you get that error when you insert into your ilines table? It is probably a problem with your insert statement. Or your call to the SP that does the insert.Be One with the OptimizerTG |
 |
|
|
heavymind
Posting Yak Master
115 Posts |
Posted - 2009-03-10 : 05:52:40
|
quote: Originally posted by sodeep Do you have table named dbo.ILines?
are you sure it's a table this seems to be a view.select * from sys.objectswhere name like '%ILines'Thanks, VadymMCITP DBA 2005/2008Chief DBA at http://www.db-staff.com |
 |
|
|
|