Results 1 to 4 of 4

Thread: Code Problem

  1. #1
    Join Date
    Apr 2009
    Posts
    20

    Unanswered: Code Problem

    I am trying to check on a status in table called Registration and when it is approved, I want it to insert the NRIC value into another table Houseowner. This NRIC value is obtained from the Registration table.

    I somehow get an syntax error after the word END becoz the END has a underlined red line (the sort of error which is denoted when there is a spelling error in ms word) I cant get rid of the red line. I have tried to retype the whole code, delete and recreate.. the red line keeps appearing..

    whats wrong with my codes? anyone pls advise... thankssss

    CREATE TRIGGER DBO.InsertHouseOwner
    ON DBO.Registration
    AFTER UPDATE , INSERT
    AS
    BEGIN
    IF(StatusofAppln = "Approved")
    BEGIN
    INSERT INTO HouseOwner (NRIC)
    SELECT (NRIC)
    FROM INSERTED

    END
    GO

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    For every BEGIN you need an END. If you properly indent your code you would spot it immediately. I can't tell if your code is indented - you should use the code tags when you post code.

    That isn't your only error, but it's the one what you have spotted
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Apr 2009
    Posts
    20
    Ok I am sorry about the codes... will take note of it in future..
    and yes i missed out an end.. and i do have other errors..
    i am just new to triggers and i cant seem to get the hang of it. argh...

    thanks anyway.

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Code:
    INSERT INTO HouseOwner (NRIC)
    SELECT NRIC
    FROM INSERTED
    WHERE StatusofAppln = "Approved"
    BTW - I wouldn't do this the way you are doing it. For example, what if status is changed back from Approved, or the original row is deleted?
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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