Useing variables in a select statement

41 views
Skip to first unread message

James Harvie

unread,
May 17, 2013, 9:57:56 AM5/17/13
to mapi...@googlegroups.com
Hello All,
 
I am a veterane user of MI Pro but very new to developing MB programs, I hope you can help on this.  I am wanting to read from a configuration file (.TXT) file the "Where" components of a Select statement into a variable and then run the Select statement using the variable name.  So for example, the statement …

 

Select * from Landuse where CATEGORY=”MIXED” into TT2

 

.. would read in MB code as the following.

            Select * from Landuse where XX into TT2

 
I have no trouble reading the "Where" part of the select statement  into a variable as CATEGORY=”MIXED” but when I run the program, all records in the Landuse table are being selected not just the ones that are classified as Mixed.  Can you help with what I am doing wrong.
 
Thanks in advance
Jamie
 
 

Thomas Bacon

unread,
May 17, 2013, 10:14:18 AM5/17/13
to mapi...@googlegroups.com

Hi Jamie,

 

You are nearly there. You need to build up the sql command as a string and then execute the string with run command. At the moment, MapInfo would interpret your sql as:

 

Select * from Landuse where "CATEGORY=""MIXED""" into TT2

 

This is interpreted by MapInfo as being true for all records. I’m not entirely sure why, but I assume it is because you are not comparing a field to anything but simply inserting a string into the where condition.

 

By building up the command as a string first, you can avoid this problem. This method essentially ‘hard-codes’ the string from XX into the command string which you can then run using the Run Command statement:

 

Dim sCmd as String

 

sCmd = "Select * from Landuse where " & XX & " Into TT2"

Run Command sCmd

 

Hope this helps,

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

--
--
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/groups/opt_out.
 
 



Mouchel logo

Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX.  The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. 

James Harvie

unread,
May 17, 2013, 4:48:08 PM5/17/13
to mapi...@googlegroups.com
Thanks Tom,
 
I bet this will do the trick
 
Jamie

Craig Slawson

unread,
May 20, 2013, 10:27:08 AM5/20/13
to mapi...@googlegroups.com
Further to Toms explanation you might find problems using double quotes in both the variable and in the Select Statement - try using single quotes for one of them if it doesn't work, if I have to include double quotes, then I usually set them up as a function, but this would require your 'CATEGORY=”MIXED”' to be two variables of 'CATEGORY' and 'MIXED' which might mean a complete rewriting of your routine, please come back to me if you need this explaining more clearly!

Craig
> --
> --
> 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/groups/opt_out .
>
>
>

--
__________________________________________________
G.Craig Slawson B.Sc. (Hons)
Ecological Records Co-ordinator
Staffordshire Ecological Record
Tel: 01889 880100; Fax: 01889 880101
E-mail: cr...@staffs-ecology.org.uk or in...@staffs-ecology.org.uk
Staffordshire Wildlife Trust Registered Office: The Wolseley Centre,
Wolseley Bridge, Stafford, ST17 0WT.
Registered as a company in England & Wales number 959609.

Reply all
Reply to author
Forward
0 new messages