Tjhb, I mostly gave up on the SQL route, because the Selected(I) column is not available in the SQL Server table, I think it's created together with all the rest of the intrinsic columns when you load and link the Geom(I) into Manifold.
Anyhow thanks for your suggestions. I did it the "easy" way, with script and simple comment component to keep the state of my MaxGroupID.
Here the code snippet that I added as an addin button in Manifold. The user selects a group of buildings, then they click on the button, the buildings are then updated with a unique GroupID which is incremented with +1. I had some issue with the ID column, it's re-generated each time I refresh data from the SQL DB, so I use a SQL based ID2 column that is fixed for each building. A theme was used to show the user which buildings they already grouped.
Sub Main
dim comp, comps
dim qry, objs, obj
dim cmpMaxGroupID,strMaxGroupID
dim tmpID2
dim r
set comps = Document.ComponentSet
set comp = comps("IndexMap v1.2")
if comps.ItemByName("tmpQuery") < 0 then
set qry = Document.NewQuery("tmpQuery")
else
set qry = comps.Item("tmpQuery")
end if
if comps.ItemByName("MaxGroupID") < 0 then
set cmpMaxGroupID = Document.NewComments("MaxGroupID")
else
set cmpMaxGroupID = comps.Item("MaxGroupID")
end if
set objs = comp.Selection
if objs.Count < 1 then
Application.MessageBox "No Buildings Selected", "Error"
exit sub
else
if len(cmpMaxGroupID.Text) > 0 then
' Get current Max GroupID
strMaxGroupID = cmpMaxGroupID.Text
else
Application.MessageBox "No MaxGroupID", "Error"
exit sub
end if
strMaxGroupID = strMaxGroupID + 1
'Application.MessageBox strMaxGroupID,""
for each obj in objs
set r = obj.Record
tmpID2 = r.DataText(2) & "," & tmpID2
'Application.MessageBox r.DataText(2),""
next
tmpID2 = left(tmpID2,len(tmpID2)-1)
'Application.MessageBox tmpID2,""
qry.Text = "update [IndexMap v1.2 Table] SET [GroupID] = " & strMaxGroupID & " WHERE [ID 2] IN (" & tmpID2 & ")"
qry.RunEx True
qry.Text = ""
Application.StatusText = "Updated " & cStr(objs.Count) & " Buildings with GroupID = " & strMaxGroupID
' Update current Max GroupID
cmpMaxGroupID.Text = strMaxGroupID
end if
End Sub