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 2000 Forums
 SQL Server Development (2000)
 simple trigger,

Author  Topic 

marconi8
Yak Posting Veteran

73 Posts

Posted - 2003-05-07 : 11:49:34
hm, i cannot update inserted table, hm this will be very usefull !

maybe this simple trigger i can write by another normal way ?

why in mssql i cannot edit (update) inserted table,
for example this type of checking will be more faster

if exists ( select value from inserted )

but i must write ar first

declare @value domain_name
select @value=value from inserted where.....
if @value = ddddd then

instead of one string i must to use 3 strings and also declare variables


maybe is any out of this situation ?








ALTER TRIGGER T_DELETE_OLD_S_PART
ON MAIN_IMAGE_LIST
FOR INSERT
AS
DECLARE @ID D_MAIN_ID,
@S_PART D_MAIN_IMAGE_LIST_S_PART,
@OVNER_ID D_MAIN_ID
BEGIN
SELECT @ID=ID,
@S_PART=S_PART,
@OVNER_ID=OVNER_ID
FROM INSERTED

IF @S_PART='TEMA'
BEGIN
UPDATE MAIN_IMAGE_LIST
SET S_PART=''
WHERE OVNER_ID=@OVNER_ID
AND
S_PART='TEMA'
AND
ID!=@ID
END


END




thanks

X002548
Not Just a Number

15586 Posts

Posted - 2003-05-07 : 12:06:53
Not sure I understand...how does:


IF (SELECT COL FROM INSERTED) = ddddd
BEGIN
..some code
END


work for you? Realize though that the Inserted virtual table may have multiple rows (I Think).


Brett

8-)

Edited by - x002548 on 05/07/2003 12:07:37
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-05-07 : 12:07:11
You can do

if exists (select * from inserted where value = 'ddddd')

You cannot update the inserted table because it is a view of the new data in the affected rows (i.e. of something that has already happenned). You can update the rows in the table but not the inserted table.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -