0

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

DBNewbie
  • 1
  • 3

1 Answers1

1

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
Rick James
  • 80,479
  • 5
  • 52
  • 119