akiles99
asked on
Trigger for date
Hi guys,
I need to write a trigger on mssql...The scenario is pretty simple.
I have two tables namely customer & dealer...
Customer has the following columns
ondate datetime
rectype varchar(20)
etc...
Dealer has the follwing columns
ULSTORDAGE varchar(20)
etc...
Now what i need is when i insert or update a row in table customer the trigger has to fire.
sales activity means the rectype='S'.
Trigger:To populate the field with the number of days since the last sales activity of the
contact record.
How:
This will come from the table (Customer) as the total number of days elapsed since their
last order or sales activity, in reverse, from today. This would be adjusted for each day going
forward and will require an automatic update each day.
Using a RecType Code of S and the ONDATE field as the evaluation field.
Update the Dealer table in column named ULSTORDAGE.
I mean ondate value difference(the date going to be inserted/updated & the previous last sales date)
has to be stored in ULSTORDAGE.
Cheers...
akiles
I need to write a trigger on mssql...The scenario is pretty simple.
I have two tables namely customer & dealer...
Customer has the following columns
ondate datetime
rectype varchar(20)
etc...
Dealer has the follwing columns
ULSTORDAGE varchar(20)
etc...
Now what i need is when i insert or update a row in table customer the trigger has to fire.
sales activity means the rectype='S'.
Trigger:To populate the field with the number of days since the last sales activity of the
contact record.
How:
This will come from the table (Customer) as the total number of days elapsed since their
last order or sales activity, in reverse, from today. This would be adjusted for each day going
forward and will require an automatic update each day.
Using a RecType Code of S and the ONDATE field as the evaluation field.
Update the Dealer table in column named ULSTORDAGE.
I mean ondate value difference(the date going to be inserted/updated & the previous last sales date)
has to be stored in ULSTORDAGE.
Cheers...
akiles
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when i execute the trigger It tells that Msg 155, Level 15, State 1, Procedure tr_mytriggername, Line 8
'd' is not a recognized datediff option.
Please fix it....
'd' is not a recognized datediff option.
Please fix it....
thats odd...try this instead
set ulstordage = datediff(day, i.ondate, getdate())
set ulstordage = datediff(day, i.ondate, getdate())
ASKER
Yeah it's working fine now....Thanks ...
great.
ASKER
i have a column which stores the (datetime)....I want to retreive only the last year...how come?
what do you mean?
ASKER
suppose i have a column name udate..
UDATE
1/7/2008 12:00:00 AM
3/29/2008 12:00:00 AM
6/10/2008 12:00:00 AM
4/11/2008 12:00:00 AM
I want to find the Year to Date for the current year....
UDATE
1/7/2008 12:00:00 AM
3/29/2008 12:00:00 AM
6/10/2008 12:00:00 AM
4/11/2008 12:00:00 AM
I want to find the Year to Date for the current year....
ASKER
If a set of sales occured before 1/1/2008, then it would not be part of this year to date sales.....
so for all sales(another column in same table) done between 1/1/2008 and 31/12/2008 i need a total?
then the data would move to the field in another table (field anme: ULYRSALES ) when the System date turned past 1/1/2009 etc using trigger........
ASKER
thanks
ASKER
Also please check it ....
https://www.experts-exchange.com/questions/23589443/mssql-help.html