我正在尝试在OBDC的表达式构建器SQL命令中运行变量。
表达式如下所示
"SELECT Date(Curdate()) AS 'Load Date',
Sum(CASE
WHEN pomstatus = 'TBR'
AND Date(portdate) < Curdate() THEN 1
ELSE 0
END) AS 'Total Removes',
Min(CASE
WHEN pomstatus = 'TBR' THEN portdate
ELSE 'N/A'
END) AS 'Oldest Removes',
Sum(CASE
WHEN pomstatus = 'TBR'
AND Date(portdate) < Curdate()
AND Date(portdate) > Subdate(Curdate(), @[User::Days] )THEN 1
ELSE 0
END) AS 'Total New Removes',
Sum(CASE
WHEN pomstatus = 'TBR'
AND acctype = 'b'
AND Date(portdate) < Curdate() THEN 1
ELSE 0
END) AS 'SOHO Removes',
Sum(CASE
WHEN pomstatus = 'C-U'
AND Date(dd) < Curdate() THEN 1
ELSE 0
END) AS 'Total Confirmed U',
Min(CASE
WHEN pomstatus = 'C-U' THEN dd
ELSE 'N/A'
END) AS 'Oldest Confirmed U',
Sum(CASE
WHEN pomstatus = 'C-U'
AND discoservice LIKE '%s%'
AND Date(dd) < Curdate()THEN 1
ELSE 0
END) AS 'Total Confirmed Satellite',
Min(CASE
WHEN pomstatus = 'C-U'
AND discoservice LIKE '%s%' THEN dd
ELSE 'N/A'
END) AS 'Oldest Confirmed Satellite',
Sum(CASE
WHEN pomstatus = 'C-U'
AND Date(dd) < Curdate()
AND Date(dd) > Subdate(Curdate(), @[User::Days] ) THEN 1
ELSE 0
END) AS 'Total New Confirmed U',
Sum(CASE
WHEN pomstatus = 'pwo' THEN 1
ELSE 0
END) AS 'Total Pending WO',
Sum(CASE
WHEN pomstatus = 'etbr' THEN 1
ELSE 0
END) AS 'Total Escalated TBR',
Sum(CASE
WHEN pomstatus = 'wtnr' THEN 1
ELSE 0
END) AS 'Total Waiting TNR'
FROM POM.mainorders
WHERE acctype <> 'c';"
我收到以下错误:
错误弹出
我测试了相同的脚本,但用数字2替换了2个变量并且它成功了,所以我知道脚本本身正在工作。在我看来,变量没有正确传递。
至于我如何填充变量,变量将从下面的执行SQL任务填充:
执行SQL任务
执行SQL任务
查询构建器结果
答案 0 :(得分:2)
它无法识别字符串
中的变量尝试将字符串与此连接:
strsplit(letters[i,2], split = "[|]")[[1]]
就个人而言,我会在数据库中创建一个存储过程并传递这两个参数,但不是每个人都有权这样做。
答案 1 :(得分:0)
这不是参数如何与执行SQL任务一起使用。
您可以使用字符串连接作为@KeithL建议或将变量(@ [User :: Days])正确映射到参数(取决于您的提供者 - 基于序数的?
标记或命名参数{{1 }})
由于您的提供程序指示OLE DB,您需要使用@myvalue
作为占位符,然后它将成为基于0的序数系统。单击参数映射,参数名称为?
,变量为0
另见Book OnLine - Map Query Parameters to Variables in an Execute SQL Task