If column does not exist add column in MB

14 views
Skip to first unread message

Matthew Hirsch

unread,
Jul 1, 2024, 2:52:07 PM (2 days ago) Jul 1
to MapInfo-L
I am trying to see if it is possible to search an opened table to see if a column exists and if it does not, adding the column.

The file is named "Payroll01012024".
The columns I want to find are "Netpay", "Gross", "Deductions", and "Tax"

If they are not there, I want to add them.  If they are there, move to the next column to check/add.
I saw an really old conversation about building functions, but it seemed to spawn an argument on best solution and was not specific in the coding so I figured I'd ask again and give exact names to work into the solution.

Thank you.

Peter Horsbøll Møller

unread,
Jul 2, 2024, 2:44:49 AM (yesterday) Jul 2
to mapi...@googlegroups.com
Hi Matthew

You can use this function to check if a column exists and if it doesn’t add it with the Alter Table statement.

Function COLExists(ByVal sTab As String, ByVal sCol As String) As Logical
 
Like this:
If Not COLExists("Payroll01012024", "Netpay"
   Alter Table Payroll01012024
      (Add Netpay Integer)
End Id

Either include the COLUMNLib module in your MapBasic project or copy and paste the function into your MapBasic source file.

Grab the COLUMNLib module on GitHub.

Peter Horsbøll Møller
Peter Horsbøll Møller
Principal Sales Engineer - Distinguished Engineer

 


Den 1. jul. 2024 kl. 20.52 skrev Matthew Hirsch <mrhr...@gmail.com>:



This message originated Externally. Use proper judgement and caution with attachments, links, or responses.


--
--
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/34602e7d-1309-4865-8408-639d821d9d8dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages