我尝试使用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是脚本中的声明参数
答案 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