Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

HELP SQL TRIGGER Expand / Collapse
Author
Message
Posted Tuesday, March 11, 2014 10:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 10:01 AM
Points: 2, Visits: 0
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
Post #1549829
Posted Tuesday, March 11, 2014 10:20 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 1:04 PM
Points: 13,086, Visits: 12,553
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1549838
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse