How can I stop script execution if insert value is null and set value if not null? I have tried to use Case and SET NOEXEC ON but get the following errors:


  Syntax Error: unexpected 'SET' (set)
  Syntax Error: missing 'closing parenthesis'  


INSERT INTO tag (table, repr, tag, value)
    SELECT 'product' AS table,
           @Id AS repr,
           'product_code' AS tag,
           CASE @Code       
             WHEN NOT null THEN @Code
             ELSE SET NOEXEC ON
           END AS value`


@Id and @Code are declared parameters in the script
SET NOEXEC ON is not MySQL syntax.

The thing to do is to avoid selecting it:

INSERT INTO tag (table, repr, tag, value)
    SELECT 'product' AS table,
            @Id AS repr,
            'product_code' AS tag,
            @Code AS value`        -- The WHERE will prevent nulls
        WHERE @Code IS NOT NULL;   -- avoid generating anything to insert when NULL