Help with SQL syntax

LO7.3.6 Win10, HSQL2.5.1

Hello,

Trying to create a macro which will append monthly transactions from one to another table and can not figure out where the mistake or missing part in the code is.

If below is run from Tools, SQl I get an - 1: unexpected token: FROM required: ) error

INSERT INTO “tblStatements” (“acc”,“mid”,“member”,“age”, “Fcat”, “pu”, “pterms_fk”) SELECT (“acc”,“mid”,“age”,“Fcat”,“pu”,“pterms_fk” FROM “vaqt”)

If run from inside a macro

Sub Testing
oConn = ThisDatabaseDocument.DataSource.getConnection("","")
SQL=oConn.createStatement()
result=SQL.executeQuery(“INSERT INTO ““tblStatements”” (”“acc”","“mid”","“member”","“age”", ““Fcat””, ““pu””, ““pterms_fk””, ““billto”” )_
“SELECT (”“acc”","“mid”","“age”","“Fcat”","“pu”","“pterms_fk”","“billto”" FROM ““vaqt””"")
End Sub

I get - BASIC syntax error.
Expected: ".

Would be grateful if someone can spot the error, thanks

two errors:

  1. you do not select the column “member” but attempt to insert it.
  2. you enclosed the columns to be inserted in parenthesis.

assuming that the column “member” does exist in both tables then:

insert into "tblStatements"
("acc","mid","member","age","Fcat","pu", "pterms_fk","billto")
select "acc","mid","member","age","Fcat","pu","pterms_fk","billto" from "vaqt"

I will leave the chore of double quoting, required by the macro, to you.

EDIT:
I did not look at your macro code before answering but it also contains errors.
Try This:

Sub Test
	oCon = ThisDatabaseDocument.DataSource.getConnection("","")
	sSQL = "insert into ""tblStatements""(" &_
	"""acc"",""mid"",""member"",""age"",""Fcat"",""pu"",""pterms_fk"",""billto"")" &_
	"select ""acc"",""mid"",""member"",""age"",""Fcat"",""pu"",""pterms_fk"",""billto"" from ""vaqt"""

	oStatement = oCon.createstatement
	oStatement.executeupdate(sSQL)
End Sub
1 Like

Thank you very much cpb, working fine now.