IF Then Else statement to update a column

1,451 views
Skip to first unread message

bec.ali...@gmail.com

unread,
May 5, 2015, 6:38:52 AM5/5/15
to mapi...@googlegroups.com
Hi there, I have a column in a table "Dev_current_5yr_2D" that I want to update based on a couple of conditions. I have been trying write an IF THEN ELSE type statement in MapBasic but get an error saying "Unrecognised command:if." I am guessing I am missing something (or multiple things) at the start.

The table I am trying to work with is "Dev_current_5yr_2D", the column/field I am trying to update is "Manhole_Performance", and I am trying to do it based on conditions met using the fields "DEPNOD", "ground_level", and "Surcharge" (all of which are in the table "Dev_current_5yr_2D"). So the command I have written is as follows:


If Dev_current_5yr_2D.DEPNOD > Dev_current_5yr_2D.ground_level then 
Dev_current_5yr_2D.Manhole_Performance = 3 

elseif Dev_current_5yr_2D.Surcharge < 0 then 
Dev_current_5yr_2D.Manhole_Performance = 2 

else 

Dev_current_5yr_2D.Manhole_Performance = 1 

endif


i would be grateful for any assistance as I have 16 tables to update and it would be awesome to not have to go via Excel. Thanks heaps.

kind regards

Ali

Deryck Brown

unread,
May 5, 2015, 6:54:33 AM5/5/15
to mapi...@googlegroups.com
Hi,

This couldn't be as simple as correctly ending your IF-statement with "End If" (with a space) could it?

Deryck

Lars I. Nielsen (GisPro)

unread,
May 5, 2015, 7:01:31 AM5/5/15
to mapi...@googlegroups.com
You're going about it in the wrong manner, as MIPro SQL is limited. E.g., you cannot make an update on a dynamic selection (Update .. Where ..), but have to first create a temp selection, and then update this.

You break it down into individual tasks, and run them logically "backwards":

'update all initially to lowest value
Update Dev_current_5yr_2D Set Manhole_Performance = 1

Select * From Dev_current_5yr_2D where Surcharge < 0
Update Selection Set Manhole_Performance = 2

Select * From Dev_current_5yr_2D where DEPNOD > ground_level
Update Selection Set Manhole_Performance = 3

HTH


Best regards / Med venlig hilsen
Lars I. Nielsen
GIS & DB Integrator
GisPro
--
--
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.
For more options, visit https://groups.google.com/d/optout.

bec.ali...@gmail.com

unread,
May 5, 2015, 5:05:30 PM5/5/15
to mapi...@googlegroups.com, L...@gispro.dk
Hi Lars, that worked perfectly thanks. And thanks for showing me a different approach to the problem too! 

Kind regards

Ali
Reply all
Reply to author
Forward
0 new messages