I have added a field called Stock to a Data Blaze table called YarnRange and am trying to create a snippet to update the stock value up or down for a row called Ref. I tried AI Write but that didn't work. Any advice would be welcome. Thanks, Tony
You can use the simple {dbupdate} command and increment the value for a specific row with the following approach: field=field+1 or decrement field=field-1. I've added a small example below.
The snippet below will increment stock (i.e. add 1) for a row with name = Ref.
{dbselect: select name, stock from Table1; space=id; multiple=yes}
{=name}
{=stock}
{dbupdate: update Table1 set stock=stock+1 where name="Ref"; space=id}
Thanks Mansur. I wasn't clear that Ref is actually the column name, not the row. However, I have amended your snippet as below to also allow for variable + / -. Thanks for your help.
{dbselect: SELECT Ref, Stock FROM Range ORDER BY number; space=1IHeI043ip48EwKEPxb3ie; multiple=no; menu=yes}
Yarn Ref: {=ref} Current Stock: {=stock}
Adjustment:
{formtext: name=adj; default=-1; cols=8}
{dbupdate: update Range set stock=stock+@adj where ref=@Ref; space=1IHeI043ip48EwKEPxb3ie}