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
 General SQL Server Forums
 New to SQL Server Programming
 Triggers and procedures
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

forrestgump
Starting Member

18 Posts

Posted - 02/12/2013 :  04:57:23  Show Profile  Reply with Quote
Not sure if I am asking the right question but would it be possible to run the below code so when information in my tables is updated the code below automatically runs?

DELETE FROM Funnel;

INSERT INTO funnel
SELECT [Q2_MetMin].*
FROM Q2_MetMin;

INSERT INTO funnel
SELECT [Q3_RecApp].*
FROM Q3_RecApp;

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 02/12/2013 :  05:01:49  Show Profile  Reply with Quote
yep.. you can add this code in a procedure and call it from scheduled sql agent job. the preceding step should be the one which updates information in your tables. The job can then be scheduled as per your required schedule

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 02/12/2013 :  05:35:18  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
>> when information in my tables is updated the code below automatically runs?

Yes it would be a trigger.
What do you want to fire the trigger though?
I'm guessing it would be an update to Q2_MetMin or Q3_RecApp? That might mean a trigger on each of those tables.
This might be an issue because if someone does single row updates then the data in funnel would be deleted and inserted for each row.
You might want to consider a trigger that uses the PK of the row updated in the source tables to minimise the activity.

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

forrestgump
Starting Member

18 Posts

Posted - 02/12/2013 :  09:37:10  Show Profile  Reply with Quote
Yes I would want the updates in Q2_MetMin to fire the trigger. How do I write the correct syntax?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 02/12/2013 :  09:50:31  Show Profile  Reply with Quote
quote:
Originally posted by forrestgump

Yes I would want the updates in Q2_MetMin to fire the trigger. How do I write the correct syntax?



CREATE TRIGGER YourTrggerName
ON Q2_MetMin
FOR UPDATE
AS
BEGIN
...your code
END


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

forrestgump
Starting Member

18 Posts

Posted - 02/12/2013 :  10:39:04  Show Profile  Reply with Quote
Thanks visakh and nigel
Go to Top of Page
  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.38 seconds. Powered By: Snitz Forums 2000