Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2003
    Posts
    4

    Unhappy Unanswered: update a computed field

    dear sirs,
    this is my first contribution at you reputable forum ..

    I have a serious problem which is .. I want to create a trigger which runs at the begining of each month .. so I created a table which has a field --> formula --> month(getdate()) i tested it by changing the month in the windows calender and each time i change the month it is updated in the table when I crated a trigger i checked if update(sal_month)
    the trigger is as follows
    ========================================
    create trigger tr_update_loan
    on salary_month
    for update
    as
    if update(sal_month)
    begin
    update hr_emp_loan
    set payed = payed + one_loan , rest = rest - one_loan
    end
    =========================================
    it returned an error "Column 'sal_month' cannot be used in an IF UPDATE clause because it is a computed column."
    I tried to not to use if update() but when I change the date in the calender it is not updated in the other table

    can any one help my in this because I'm doing my graduation project

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    You should be using a scheduled job to carry out such kind of tasks , not a trigger.
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    Dec 2003
    Posts
    4

    Lightbulb please if you can describe more

    Originally posted by Enigma
    You should be using a scheduled job to carry out such kind of tasks , not a trigger.
    sorry please if you can describe more because I didn't understand
    thank you in advance for your cooperation

  4. #4
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    As far as I understand,since this is a thing which will be done monthly , (i.e. when the month changes) you should write a stored procedure to make the required updates. This stored procedure should be scheduled to be executed as a job on the particular time i.e. day of month on which you want it to run. You can schedule a job by going to Enterprise Manager --> Server --> Management --> SQL Server Agent --> Jobs
    Last edited by Enigma; 12-29-03 at 08:00.
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  5. #5
    Join Date
    Dec 2003
    Posts
    4

    Smile tahnks

    thank you for your fast response I'll try it because it will be my first time dealing with this item so I'll try it and tell you what happened .. thank you again enigma (.. I saw your site ..)

    Originally posted by Enigma
    As far as I understand,since this is a thing which will be done monthly , (i.e. when the month changes) you should write a stored procedure to make the required updates. This stored procedure should be scheduled to be executed as a job on the particular time i.e. day of month on which you want it to run. You can schedule a job by going to Enterprise Manager --> Server --> Management --> SQL Server Agent --> Jobs

  6. #6
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Thanks for viewing my site !!! At least somebody visited it after a long time
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  7. #7
    Join Date
    Dec 2003
    Posts
    4

    Talking It worked

    Thank you very much it worked

    Originally posted by Enigma
    Thanks for viewing my site !!! At least somebody visited it after a long time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •