Home All Groups Group Topic Archive Search About

Help with CREATE TRIGGER syntax

Author
16 Sep 2005 7:41 PM
mike
Any help would be appreciated. What's wrong with the following syntax?


CREATE TRIGGER tr_CMR_Client_Status_Confirm
ON [CMR Client Numbers]
FOR INSERT, UPDATE
        AS
    IF UPDATE [Current Status]
                    CASE WHEN [Current Status] = 'X' THEN [Status Flag] = [CMR
Client Number ID] ELSE [Status Flag] = NULL END

Author
16 Sep 2005 8:01 PM
Trey Walpole
1. IF UPDATE should have parentheses around the column name - note: if
any row's [Current Status] is updated, this will evaluate to true.
2. not a syntax error, but for clarity, should put a BEGIN..END after the IF
3. [biggest problem] There's no DML statement to do anything, just a
CASE expression...
4. ... which is incorrectly written

Look up UPDATE, CREATE TRIGGER and CASE in BOL

It is quite unclear from the code given what table the [Status Flag]
column belongs to, otherwise I could give an example of possible correct
trigger code.
Please provide DDL of the table.

mike wrote:

Show quote
>Any help would be appreciated. What's wrong with the following syntax?
>
>
>CREATE TRIGGER tr_CMR_Client_Status_Confirm
>ON [CMR Client Numbers]
>FOR INSERT, UPDATE
>        AS
>    IF UPDATE [Current Status]
>                    CASE WHEN [Current Status] = 'X' THEN [Status Flag] = [CMR
>Client Number ID] ELSE [Status Flag] = NULL END
>
>
>
>
>

>
Author
17 Sep 2005 9:27 AM
David Portas
What are you trying to do? It looks like you want to duplicate a value in
another column of your table, which isn't a good thing to do.

Please post DDL and sample data.

--
David Portas
SQL Server MVP
--

AddThis Social Bookmark Button