数据库可选参数错误

时间:2015-10-13 22:50:30

标签: sql database mule

我的动态查询出现问题,因为我有一些空值。如果它没有任何值,我已经使值可选,但我仍然得到错误。有什么想法吗?

这是我对数据库连接器的动态查询。我认为问题出在BROKER和COTTON组织声明

insert into [AWH_PrjPathFinder].[dbo].[ws_balesDataExt] values ('#[payload['FULLDATE']]', '#[payload.BROKER = (payload['BROKER'] == null) ? '' : payload.BROKER.toString()]', '#[payload.CENTER = ( payload['CENTER'] == null) ? '' : payload.CENTER.toString()]', '#[payload.DATATYPE = ( payload['DATATYPE'] == null) ? '' : payload.DATATYPE.toString()]','#[payload.COTTONORG = (payload['COTTONORG'] == null) ? '' : payload.COTTONORG.toString()]',#[payload['UNIT']],'#[payload['dateDataEnteredInAGDB']]')

这是我的示例输入文件。

[ {
"FULLDATE": "28/09/2015",
"CENTER": "B",
"DATATYPE": "CDLV",
"UNIT": "195" },
{
"FULLDATE": "28/09/2015",
"CENTER": "M",
"DATATYPE": "CRCV",
"UNIT": "47"
},
{
"FULLDATE": "28/09/2015",
"CENTER": "M",
"DATATYPE": "CRCV",
"UNIT": "60"
},
{
"FULLDATE": "28/09/2015",
"CENTER": "M",
"DATATYPE": "DDMP",
"UNIT": "84"
 },
 {
 "FULLDATE": "28/09/2015",
"CENTER": "M",
"DATATYPE": "DRCV",
"UNIT": "24"
  },

1 个答案:

答案 0 :(得分:1)

在形成插入时,您应该始终指定列(按照正确的顺序)(以及Gordon Linoff提出的这一点)。

e.g。 (下面的第二行已添加 - 这是猜测)

INSERT INTO [AWH_PrjPathFinder].[dbo].[ws_balesDataExt] 
    ([FULLDATE],[BROKER],[CENTER],[DATATYPE],[COTTONORG],[UNIT],[dateDataEnteredInAGDB])
VALUES 
      (   '#[payload['FULLDATE']]'
        , '#[payload.BROKER = (payload['BROKER'] == null) ? '' : payload.BROKER.toString()]'
        , '#[payload.CENTER = ( payload['CENTER'] == null) ? '' : payload.CENTER.toString()]'
        , '#[payload.DATATYPE = ( payload['DATATYPE'] == null) ? '' : payload.DATATYPE.toString()]'
        , '#[payload.COTTONORG = (payload['COTTONORG'] == null) ? '' : payload.COTTONORG.toString()]'
        , '#[payload['UNIT']]
        , '#[payload['dateDataEnteredInAGDB']]'
      )