openblocks
openblocks copied to clipboard
[Feature Request] UPSERT for MSSQL
I think that MSSQL doesn't support out of the box the UPSERT comand, and that is why it is very annoying having to write the query by hand.
UPDATE dbo.salesProduction_MA_SaleOrd set
notesSales={{form_upsertOrd.data.notesSales}},
notesProduction={{form_upsertOrd.data.notesProduction}},
dateSales=CONVERT(DATETIME2,nullif({{form_upsertOrd.data.dateSales===""? NULL:form_upsertOrd.data.dateSales}},'NULL')),
dateProduction=CONVERT(DATETIME2,nullif({{form_upsertOrd.data.dateProduction===""? NULL:form_upsertOrd.data.dateProduction}},'NULL')),
allowBackOrder={{form_upsertOrd.data.allowBackOrder===""? NULL:form_upsertOrd.data.allowBackOrder}}
where internalOrdNo LIKE {{tableOrderHead.selectedRow.internalOrdNo}}
if @@ROWCOUNT = 0
INSERT into dbo.salesProduction_MA_SaleOrd (internalOrdNo,notesSales,notesProduction,dateSales,dateProduction,allowBackOrder) values ({{tableOrderHead.selectedRow.internalOrdNo}},{{form_upsertOrd.data.notesSales}},{{form_upsertOrd.data.notesProduction}},
CONVERT(DATETIME2,nullif({{form_upsertOrd.data.dateSales===""? NULL:form_upsertOrd.data.dateSales}},'NULL')),
CONVERT(DATETIME2,nullif({{form_upsertOrd.data.dateProduction===""? NULL:form_upsertOrd.data.dateProduction}},'NULL'))
,{{form_upsertOrd.data.allowBackOrder===""? NULL:form_upsertOrd.data.allowBackOrder}});
In my case i had to convert the datetime and simultaneously check if the field was empty.
CONVERT(DATETIME2,nullif({{form_upsertOrd.data.dateSales===""? NULL:form_upsertOrd.data.dateSales}},'NULL')),
it would be really great if you could have this feature in the GUI query, for both single and bulk UPSERT.
Thank you!