SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sqlfresher2k7
Aged Yak Warrior

583 Posts

Posted - 07/09/2012 :  17:37:16  Show Profile  Reply with Quote

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


  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000