HELP SQL TRIGGER

  • CAN SOMEONE tell me what is wrong with this code

    I have two tables LicParcela, and LicKo , I want, when i Draw ( insert) new Parcela ( Polygon type), to check in With LiKo (Polygon) is, and to give LicParcela.LicKoId that Id of LicKo

    CREATE TRIGGER ubacujeKoIdZaParcelu

    ON dbo.LicParcela

    AFTER INSERT,UPDATE

    AS

    BEGIN

    DECLARE @C int

    SET @C=(SELECT LicKo.LicKoId FROM LicKo,LicParcela

    WHERE LicKo.geom.STContains(LicParcela.geom)=1

    )

    UPDATE LicParcela

    SET LicParcela.LicKoId=@c

    END

    GO

    Thank you forward

  • milutinke (3/11/2014)


    CAN SOMEONE tell me what is wrong with this code

    I have two tables LicParcela, and LicKo , I want, when i Draw ( insert) new Parcela ( Polygon type), to check in With LiKo (Polygon) is, and to give LicParcela.LicKoId that Id of LicKo

    CREATE TRIGGER ubacujeKoIdZaParcelu

    ON dbo.LicParcela

    AFTER INSERT,UPDATE

    AS

    BEGIN

    DECLARE @C int

    SET @C=(SELECT LicKo.LicKoId FROM LicKo,LicParcela

    WHERE LicKo.geom.STContains(LicParcela.geom)=1

    )

    UPDATE LicParcela

    SET LicParcela.LicKoId=@c

    END

    GO

    Thank you forward

    Two major issues here. First is you are not referencing either INSERTED or DELETED. And second is that your code is unable to handle multiple row modifications.

    Before we can offer more detailed help you will need to provide some more details:

    1. Sample DDL in the form of CREATE TABLE statements

    2. Sample data in the form of INSERT INTO statements

    3. Expected results based on the sample data

    Please take a few minutes and read the first article in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

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

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