Mapbasic - Add duplicate rows based on count column.

33 views
Skip to first unread message

Matthew Hirsch

unread,
May 21, 2022, 6:01:21 PM5/21/22
to mapi...@googlegroups.com

Is it possible to duplicate rows based on a count column?

 

For example, if I had a table with Blockgroup and Count columns, is it possible for MB to see BG1 has 4 in the count and will add 3 new BG1 rows?  

 

Turn this:

BG – Count

BG1-4

 

Into this:

BG

BG1

BG1

BG1

BG1

 

I know this seems very counterproductive, but I am trying to code around a script that is looking for separate rows for each entry rather than a summed up number.

 

Thank you.

 

Matthew

Uffe Kousgaard

unread,
May 22, 2022, 3:00:32 AM5/22/22
to mapi...@googlegroups.com
Hi,

You can try this code:

include "mapbasic.def"
open table "inputT"
commit table inputT as "outputT"
open table "outputT"
dim i, j as integer
for i = 1 to tableinfo(outputT,TAB_INFO_NROWS)
  select * from outputT where rowid=i into tmp1 noselect
  for j = 1 to tmp1.count-1
    insert into outputT select * from tmp1
  next
next
drop table tmp1

You may need a different column name than count - it may be reserved within SQL.
Finally sort the records, if required, by an ID.

Regards
Uffe Kousgaard
--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapinfo-l/PH0PR04MB8337CF8928A15D54D884E00FABD29%40PH0PR04MB8337.namprd04.prod.outlook.com.

Reply all
Reply to author
Forward
0 new messages