sql sum issue syntax

Hello.

I’m trying to sum a column by a table in db sql and put the result into a variable, but my code doesn’t work. Can anyone solve and tell me where is my syntax error?

function sum () local xyz = 0 local sums = "SELECT SUM (import) as = '".. xyz .."' FROM Tables '" db:exec( sums ) print (xyz) end

This should do the trick.

[lua]

local function sum()

      local xyz = 0

      local sums = [[Select sum(import) as total from tables]]

      for row in db:nrows(sums) do

            xyz = row.total

      end

      print (xyz)

end

[/lua]

thanks for you help sir…

Now it works correctly :slight_smile:

This should do the trick.

[lua]

local function sum()

      local xyz = 0

      local sums = [[Select sum(import) as total from tables]]

      for row in db:nrows(sums) do

            xyz = row.total

      end

      print (xyz)

end

[/lua]

thanks for you help sir…

Now it works correctly :slight_smile: