Hi Sam,

There are two ways of using varaibles refering to column names in SQL statement

1. Using the Alias Variable:

Dim     Table1, Table2, Col1, Col2 As String,
        aCol1, aCol2 As Alias

        Table1  = TableInfo(1, TAB_INFO_NAME)
        Table2  = TableInfo(2, TAB_INFO_NAME)
        Col1    = ColumnInfo(Table1, "col1", COL_INFO_NAME)
        Col2    = ColumnInfo(Table2, "col1", COL_INFO_NAME)
        aCol1   = Table1 & "." & Col1
        aCol2   = Table2 & "." & Col2

        Select *
                From  Table1, Table2
                Where aCol1 = aCol2

2. Using the Run Command statement

Dim     Table1, Table2, Col1, Col2 As String

        Table1  = TableInfo(1, TAB_INFO_NAME)
        Table2  = TableInfo(2, TAB_INFO_NAME)
        Col1    = ColumnInfo(Table1, "col1", COL_INFO_NAME)
        Col2    = ColumnInfo(Table2, "col1", COL_INFO_NAME)

        Run Command "Select * From " & Table1 & ", " & Table2 & " Where " & Col1 & " = 
" & Col2

HTH
Peter Horsb�ll M�ller
GIS Developer
Geographical Information & IT
 
COWI A/S
Odensevej 95
DK-5260 Odense S.
Denmark
 
Tel     +45 6311 4900
Direct  +45 6311 4908
Mob     +45 5156 1045
Fax     +45 6311 4949
E-mail  [EMAIL PROTECTED]
http://www.cowi.dk


-----Original Message-----
From: Sam Shelley [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 18, 2004 12:50 AM
To: [EMAIL PROTECTED]
Subject: MI-L Using variables in SQL Select


Hi Listers,

 

Does anyone know how to use variables pointing to table name and column names in a 
MapBasic SQL query.  Following is and example of the section code that I am using but 
the compiler doesn't like it:

 

Table1= TableInfo(1, TAB_INFO_NAME)

Table2= TableInfo(2, TAB_INFO_NAME)

 

 

Col1 = ColumnInfo(Table1, "col1", COL_INFO_NAME)

 

Col2 = ColumnInfo(Table2, "col1", COL_INFO_NAME)

 

Select *

 

>From  Table1, Table2

Where 

 

Table1.Col1 = Table2.Col2

 

Any help would be much appreciated, as I have run into this problem before but have 
been able to get around it but this time I can't.

 

Thanks Sam

 

 


---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10930

Reply via email to