How to run trigger or procedure

  • Dear nice guys,

    I just start to write SQL Script. This is incomplete and I don't know exact syntax about that. Would anyone tell me how to create well-formed procedure or trigger with the following code. Thanks you for help!!!!!

    <code>

    DECLARE @iNumValue int, @charOldValue char(6)SELECT @iNumValue = CAST( SUBSTRING (ValueColumnName, 4, 3) AS Integer ), @charOldValue = ValueColumnName

    SET @iNumValue = @iNumValue + 1

    IF @iNumValue > 999

    BEGIN 

    Set iNumValue = 0 

    DECLARE @chOneLetter char(1)

    Set @chOneLetter = 'A'

    SELECT @chOneLetter = CHAR(ASCII(@chOneLetter) + 1)

    END

    DECLARE @charNewValue char(6)SET @charNewValue = LEFT(@charOldValue, 3) + RIGHT('000' + CAST(@iNumValue AS varchar(3), 3 )

    </code>

  • Basically add  

    CREATE TRIGGER <trigger_name>

    AS 

    at the beginning for a proc and

     CREATE TRIGGER <trigger_name>

    ON <table_name>

    FOR DELETE, INSERT, UPDATE

    AS

     

    See BOL for more information.  If you are using Query Analyzer from SQL Server 2000 when you create a new screen(CTRL N) you can select templates for the kind of query are writing.  Clean up the syntax errors in your code and you can easily create a proc from it.

     

    Francis

  • I think the best thing is to write 1 Stored procedure (not to write the trigeer on it .. or on the table ..)

    and this can be reashed by checking @@error varable after adding to table ... if it is 0 (ok) then add to the other table ..

    if you make a trigger, then with every insert in the table ... the trigger will fire (run) ... is this what you want? if yes then make the triiger ...


    Alamir Mohamed
    Alamir_mohamed@yahoo.com

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

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