如果insert值为null,如何设置值为null,如何停止脚本执行?

时间:2018-03-23 23:40:10

标签: mysql

我尝试使用Case和SET NOEXEC ON但是出现以下错误:

  

语法错误:意外'设置' (集)

     

语法错误:缺少'右括号'

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和@Code是脚本中的声明参数

1 个答案:

答案 0 :(得分:0)

SET NOEXEC ON -- is a command and not a value, so you can't use it in insert statment.

尝试下面的sql(ms - sql)


if(@Code is not null)
begin
INSERT INTO tag (table, repr, tag, value)
    SELECT 'product' AS table,
           @Id AS repr,
           'product_code' AS tag,
           @Code AS value
end