write trigger for a table

  • tables:

    --------------

    emp_att_tab(emp_id,in_time,att_date,shift_id,lunch_out_time,lunch_in_time,id)

    shift_mas_tab(shift_id,lunch_start_date)

    wht ever we inserted lunch start time in shift mas_tab,when we trying to update the attendance tab while entering the lunch out time shouldbe

    greater than lunch_starttime and update the lunch outtime in attendance tab

    i tried here the outtime is not updating in attendance table

    create trigger lunctout_time on emp_att_tab

    instead of update

    as

    begin

    declare @b-2 int,@c datetime,@shift_id int

    DECLARE @emp_id int,@lunch_start_time datetime,@lunch_out_time datetime,@in_time datetime,@id int

    set @b-2=(select shift_id from emp_att_tab where id=(select max(id) from emp_att_tab where emp_id=@emp_id))

    set @c=(select lunch_start_time from shift_mas_tab where shift_id=@b )

    if (@lunch_out_time>=@c )

    begin

    update emp_att_tab set lunch_out_time=@lunch_out_time where id=

    (select max(id) from emp_att_tab where emp_id=@emp_id)

    raiserror ('u should allow here',10,1)

    END

    else

    raiserror ('u should not allow here',10,1)

    END

  • Please attach sample data together with a more detailed description on what you're trying to achieve.

    It's not the "urgent" hint that gives you fast answers, it's the way you'll describe your problem and the data you'll provide.

    For details on how to provide sample data please follow the link in my signature.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • sagi (6/16/2009)


    write trigger for a table.i.e attendance table

    columns:emp_id,lunch_out_time,lunch_in_time

    suppose lunch_out_time=1pm

    in attendance table lunch out time should insert only after 1pm, should not insert before 1 pm

    plz send code very urgent thn'ssssssss

    duplicate post; same question was asked here:http://www.sqlservercentral.com/Forums/Topic735615-145-1.aspx

    you need to provide more information in the other post so we can help.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • sagi (6/16/2009)


    plz send code very urgent thn'ssssssss

    Show us what you have so far. I'm happy to help, but not to do the entire job for you.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply