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 2005 Forums
 Transact-SQL (2005)
 please help create trigger condition on update

Author  Topic 

midan1
Starting Member

39 Posts

Posted - 2008-06-24 : 16:30:46
please help create trigger condition on update

IF  EXISTS 
(
SELECT *
FROM empList
WHERE (unit = 9)

)
begin

update [dbo].[empList]
set unit = CASE WHEN SELECT na,empID, unit
FROM empList
WHERE (empID IN (111, 222, 333, 555)) AND (unit = 9))
then '4' else t.fld1 end


i have an emmployee table



empid unit

------------------------------------------------------

1111 3

2222 9

3333 9

4444 2

5555 2

6666 1

7777 9

8888 2

9999 9

-----------------------------

i need help create trigger condition on update like this

ONLY ON

EMPID=2222,3333,7777,9999

WHAN ON UPDATE they have unit =9 THAN

I NEED THE trigger DO THIS



empid unit

------------------------------------------------------

1111 3

2222 4

3333 4

4444 2

5555 2

6666 1

7777 4

8888 2

9999 4



ONLY IF someone update EMPID=2222 OR 3333 OR 7777 OR 9999 and UNIT=9

THAN automatic change 9 TO 4



TNX for the help

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-06-24 : 23:06:24
[code]UPDATE e
SET unit = '4'
FROM [dbo].[empList] e
INNER JOIN inserted i ON e.empID = i.empID
WHERE e.empID IN (111, 222, 333, 555)
AND i.unit = '9'
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -