I’m used to MS sql so working with mySql is sure to throw some syntax error at me that is bound to slow me down. I have the following:
declare @expensesSum DOUBLE
select @expensesSum = sum(expenseAmount) from bondsaverdb.expenses
insert into bondsaverdb.expenses
select '6','Extracash',(income - @expensesSum) from bondsaverdb.income where userName ='Dean'
The error I’m getting says:
syntax error near declare @expensesSum
Must be the way I’m declaring the variable??
Thanks in advance!
MySQL does not require (or even allow, apparently) you to
declarevariables, and as far as I know it will treat all objects, variables included, as strings — so they cannot be typed in t his way. Anyway, this should work:I’m also not sure what that
'6'is for .. if that’s an auto increment ID you should omit it from theINSERTaltogether (and specify the other columns to write to) or leave itNULL.