fernand st-georges (fernand.st-georges@videotron.ca) writes:
[quoted text, click to view] > "it is not likely to share more syntax with SQL Server than any other
> random engine"
> in fact in Sybase Anywhere I had the choice to write triggers using
> Watcom Sql which is more like natural language or Transac Sql
>
> Anywhere even translated automaticly from one to another
>
> but actually in Sql Server, the language is different and have to write
> triggers that are not in a natural language
>
> "CREATE TRIGGER MAJ_SOLDE ON [VERSEMENT]
> FOR
> UPDATE [MEMBRE]
> as
> SET [MEMBRE].SOLDE = [MEMBRE].SOLDE + [VERSEMENT] .MONTANT
> FROM [MEMBRE]
> join [CONTRAT] on [MEMBRE].NO_MEMBRE = [CONTRAT].NO_MEMBRE
> join [VERSEMENT] on [VERSEMENT] .NO_CONTRAT = [CONTRAT].NO_CONTRAT
> join inserted ON inserted.NO_CONTRAT = [VERSEMENT] .NO_CONTRAT E
> end"
>
> now the message I get Incorrect syntaxe near 'MEMBRE'
That syntax is not legal synrax in MS SQL Server, and was not legal
syntax in Sybase SQL Server last time I saw it, but I have only worked
with Sybase 4.x. Then again, looking at
http://manuals.sybase.com:80/onlinebooks/group-as/asg1250e/refman/@Generic__BookView
I see no mention of the above syntax, so I would assume that it is
specific to Sybase Anywhere.
The correct syntax in SQL Server would be:
CREATE TRIGGER MAJ_SOLDE ON [VERSEMENT]
FOR
UPDATE
as
UPDATE MEMBRE
SET SOLDE = [MEMBRE].SOLDE + [VERSEMENT] .MONTANT
FROM [MEMBRE]
join [CONTRAT] on [MEMBRE].NO_MEMBRE = [CONTRAT].NO_MEMBRE
join [VERSEMENT] on [VERSEMENT] .NO_CONTRAT = [CONTRAT].NO_CONTRAT
join inserted ON inserted.NO_CONTRAT = [VERSEMENT] .NO_CONTRAT
That is, the trigger body must have a complete UPDATE statement, you
should not prefix the column on left-hand side of the SET clause, and
the END should not be there.
You should probably remove VERSEMENT from the FROM clause as well; I
cannot see that you really need it.
--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se
Books Online for SQL Server SP3 at