Author |
Topic |
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-08 : 19:43:33
|
Good day.!I have read about trigger events in sql server. I just want to know if is it possible to create a trigger that will execute a vb script or sql server query when the data like date of the column field is less than 5 days of the current system date.?Thank you for giving time & God bless.. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-09 : 10:39:22
|
quote: Originally posted by blocker Good day.!I have read about trigger events in sql server. I just want to know if is it possible to create a trigger that will execute a vb script or sql server query when the data like date of the column field is less than 5 days of the current system date.?Thank you for giving time & God bless..
its possible. so you need this for each insert action? |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-10 : 19:33:03
|
Thank you for a helpful link..Ill try to create a trigger base on this example..Ill post it here when im done..Thank you & God bless. |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-10 : 19:36:13
|
I need this trigger to execute everytime one of the date on a table in column(entrydate)is less than 5 days of the current system date..Everytime it occurs, the trigger will execute..I still cant figure this out. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-11 : 10:53:12
|
quote: Originally posted by blocker I need this trigger to execute everytime one of the date on a table in column(entrydate)is less than 5 days of the current system date..Everytime it occurs, the trigger will execute..I still cant figure this out.
create an after update trigger on table like belowCREATE TRIGGER YourTriggerON TableAFTER UPDATEAS BEGIN... -- your code hereFROM INSERTEDWHERE Date < DATEADD(dd,DATEDIFF(dd,0,GETDATE())-5,0)END |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-11 : 20:53:49
|
thank you.Will this trigger only works when i insert data.? I have more than 500 data on the table, assuming that today's system date is January 12, 2010, when one of the data thats holds date value in sql server table is less than 5 days of the current system date, the trigger will execute even if i dont do any update, insert, or delete in the table. Will this possible?I'm trying to figure out to put some fields for date in the table to hold the current system date, when it is inserted, the trigger will execute to loop or search all the fields of the table and notify if it founds date value less than the date inserted which is the current system date.This is just an idea to do this.hehe.But if this works, what will be the trigger event to loop or search when the current system date is inserted.?Thank you guys very much for giving time.God bless us. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-11 : 23:49:25
|
Ok..thank you..so i decided to execute the tigger after update of the current system date field and then execute a stored procedure to search all date values on a certain table that is less than 5 days of the current system date.. I'll make this idea tonight. I'll post the code preferably tommorow if it works.Any more brilliant ideas from you guys is very important & helpful..May more thanks..Thank you for giving time & God bless. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-12 : 01:11:16
|
quote: Originally posted by blocker thank you.Will this trigger only works when i insert data.? I have more than 500 data on the table, assuming that today's system date is January 12, 2010, when one of the data thats holds date value in sql server table is less than 5 days of the current system date, the trigger will execute even if i dont do any update, insert, or delete in the table. Will this possible?I'm trying to figure out to put some fields for date in the table to hold the current system date, when it is inserted, the trigger will execute to loop or search all the fields of the table and notify if it founds date value less than the date inserted which is the current system date.This is just an idea to do this.hehe.But if this works, what will be the trigger event to loop or search when the current system date is inserted.?Thank you guys very much for giving time.God bless us.
you dont need loop. you can use set based solution to find records with date value less than the current system date |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-12 : 02:24:27
|
how could i do that.?? Im really confused.heheh.pls help me guys..Ill try all your help right here to the best of mine..Ok. my solution above to insert a field for current system date,run the trigger, and execute the stored procedure to find the date less than 5 of the current system date is right, but instead of using loop, i will use set based solution.? How could that be.? I still dont have knowledge about set based solution.Thank you for giving time.God bless. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-12 : 02:30:02
|
quote: Originally posted by blocker how could i do that.?? Im really confused.heheh.pls help me guys..Ill try all your help right here to the best of mine..Ok. my solution above to insert a field for current system date,run the trigger, and execute the stored procedure to find the date less than 5 of the current system date is right, but instead of using loop, i will use set based solution.? How could that be.? I still dont have knowledge about set based solution.Thank you for giving time.God bless.
1. to insert system date, you can use GETDATE()2. you can write a trigger for insert/update and inside that you can do check to find the date less than 5 of the current system date . i dont think you need separate procedure for that |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-12 : 04:00:37
|
ok.we're getting close to the solution..After I insert the current system date, i will execute the trigger which will find over 500 data of which date is less than 5 days of the current system date. Pretty close this should look like this.CREATE TRIGGER datefinderON tblcostumerorderAFTER UPDATEAS BEGINSELECT * FROM tblcostumerorderWHERE dateordered <DATEADD(dd,DATEDIFF(dd,0,GETDATE())-5,0)>ENDIf I've made something wrong on this trigger please change it to a more accurate way.If this is correct, I just want to know on how to get all the data that was returned by the sql query on this trigger event and insert it to a temporary table like tbl_temp_datefinder.Thank you guys for giving time. God bless. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-12 : 04:18:11
|
quote: Originally posted by blocker ok.we're getting close to the solution..After I insert the current system date, i will execute the trigger which will find over 500 data of which date is less than 5 days of the current system date. Pretty close this should look like this.CREATE TRIGGER datefinderON tblcostumerorderAFTER UPDATEAS BEGINSELECT * FROM tblcostumerorderWHERE dateordered <DATEADD(dd,DATEDIFF(dd,0,GETDATE())-5,0)>ENDIf I've made something wrong on this trigger please change it to a more accurate way.If this is correct, I just want to know on how to get all the data that was returned by the sql query on this trigger event and insert it to a temporary table like tbl_temp_datefinder.Thank you guys for giving time. God bless.
why do you need to put this in a temp table? what will you be doing with it? |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-12 : 04:42:40
|
after i inserted it to a temporary table, i will execute a vbscript to send sms to the corresponding customer base on that temp table..Did i made correct on my trigger.?Thank you guys for giving time.God bless |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-12 : 04:45:57
|
quote: Originally posted by blocker after i inserted it to a temporary table, i will execute a vbscript to send sms to the corresponding customer base on that temp table..Did i made correct on my trigger.?Thank you guys for giving time.God bless
you can do it from trigger itself if you wanthttp://www.siccolo.com/Articles/SQLScripts/how-to-create-trigger-to-sms-email.html |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-12 : 04:57:47
|
Ok.so i decided not to put the data in a temp table. I just want to know the syntax on how to return the data resulted from query on the trigger event.Example if it founds 10 data upon triggering. Just want also to ask if teleflip.com is free of charge or i need to register first.Thank you very much guys for a very brilliant ideas. We're almost done.Thanks God.Thank you for giving time.God bless |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-12 : 05:04:10
|
quote: Originally posted by blocker Ok.so i decided not to put the data in a temp table. I just want to know the syntax on how to return the data resulted from query on the trigger event.Example if it founds 10 data upon triggering. Just want also to ask if teleflip.com is free of charge or i need to register first.Thank you very much guys for a very brilliant ideas. We're almost done.Thanks God.Thank you for giving time.God bless
what data would you be returning for records which satisfy your condition? |
 |
|
Kristen
Test
22859 Posts |
Posted - 2010-01-12 : 05:05:07
|
Maybe I'm misunderstanding something, but don't you just need a scheduled task that performs an action where " one of the date on a table in column(entrydate)is less than 5 days of the current system date"?Scheduled task can run every minute, if you need it to, or perhaps running daily (at midnight??) would be sufficient? |
 |
|
blocker
Yak Posting Veteran
89 Posts |
Posted - 2010-01-12 : 05:21:35
|
This data would be the result of the trigger: the contactnumber, purchaseditems, and dueamount..Ive plan to run this trigger only every 25th day of the month. When the dateentered is less than five days of the current system date, it will send sms to their corresponding contactno with their purchaseditems, and dueamount. |
 |
|
Kristen
Test
22859 Posts |
Posted - 2010-01-12 : 05:44:09
|
"Ive plan to run this trigger only every 25th day of the month"Then the correct term, within SQL Server, for what you want is a "scheduled task" and not a "trigger"."Trigger" sounds find to me in English but in SQL Server you need to create a Job and Schedule it for the 25th of each month. |
 |
|
Next Page
|