Hi, I have a "SELECT TOP 1 * FROM … " query I would like to execute in a macro:
sub DoStuff()
oDBRange = thisComponent.DataBaseRanges.getByName("something")
oDesc() = oDBRange.getImportDescriptor()
For i = 0 to ubound(oDesc())
oPrp = oDesc(i)
If oPrp.Name = "DatabaseName" then
oPrp.Value = "my_db"
elseIf oPrp.Name = "SourceType" then
oPrp.Value = com.sun.star.sheet.DataImportMode.SQL
elseIf oPrp.Name = "SourceObject" then
oPrp.Value = "SELECT TOP 1 * FROM myTable ORDER BY val DESC"
elseif oPrp.Name = "IsNative" then
oPrp.Value = True
Endif
oDesc(i) = oPrp
Next
oDBRange.getReferredCells.doImport(oDesc())
end sub
Calc returns invalid SQL error for this. It is ok with the same statement withtout the "TOP 1 ".
I looked at this answer this seems to be specific to data using the UI view with forms.
Is there some way to bypass this syntax check and pass it to MSSQL Server anyway?
Or some alternate syntax?
I could add a RowNumber to the table and add a “WHERE Row = 1” to the query but I’d prefer not to touch the DB schema.
Thanks