2015-10-13 62 views
1

我的動態查詢出現問題,因爲我有一些空值。如果它沒有任何值,我已將值設置爲可選,但仍然出現錯誤。有什麼想法嗎?數據庫可選參數錯誤

這是我對數據庫連接器的動態查詢。我認爲問題出在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

您應該列出插入到'insert'語句中的所有列。 –

+1

還在收到什麼錯誤? – Morpheus

+0

在處理錯誤時添加錯誤消息(全部)&將來,在沒有我們請求的情況下請執行此操作 –

回答

1

形成刀片(&這一點由戈登·利諾夫制)時,應始終指定列(以正確的順序)。

例如(下面第二行已被添加 - 這是一個猜測)

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']]' 
    )