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)
 Query Help

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-07-09 : 17:37:16
[code]
I need a trigger on insert

Example for insert trigger:

MasterIp studentstat stustatus2 Active_status
----------------------------- ---------- -------- -------------
5.46.200.1.462222.2.1.1.1.1.1 0 0 1


If i created a record with "5.46.200.1.462222.2.1.1.1.1.1.1" then i need the stustatus2,Active_status values inherited from parent i.e "5.46.200.1.462222.2.1.1.1.1.1"


INSERT INTO MyTable (MasterIp , status1,status2,Active_status)
VALUES ('5.46.200.1.462222.2.1.1.1.1.1.1',0,1,1);

Expected output should be:

MasterIp studentstat stustatus2 Active_status
----------------------------- ---------- -------- -------------
5.46.200.1.462222.2.1.1.1.1.1 1 0 1
5.46.200.1.462222.2.1.1.1.1.1.1 0 0 1



I need a trigger for update as well.

If the updated MasterIp has childrens, set studentstat = 1 and all the children of that MasterIp should be set to the same stustatus2 and Active_status values as the parent MasterIp.

Ex: for Update trigger:


MasterIp studentstat stustatus2 Active_status
----------------------------- ------- -------- -------------
5.46.200.1.462222.2.1.1.1.1.1 0 0 1
5.46.200.1.462222.2.1.1.1.1.1.1 0 0 0


update MyTable set stustatus2=1 where masterip ='5.46.200.1.462222.2.1.1.1.1.1'

Expected output:


MasterIp studentstat stustatus2 Active_status
----------------------------- ------- -------- -------------
5.46.200.1.462222.2.1.1.1.1.1 1 1 1
5.46.200.1.462222.2.1.1.1.1.1.1 0 1 1



Please let me know if i m not clear in my explanation


Thanks for your help in advance


[/code]
   

- Advertisement -