1

私は何日も苦労してきた SQL 構文の問題を抱えています。

次のクエリから取得した CountryIP Country Formという TextBox に挿入したいという MS Access 2010 フォームを作成しました。CountryIPLocation

IPNS IPNE CY2(2 letter Country Code) CY3(3 Letter country Code) Country (full Country Name)

テーブルの行は次のようになります。

IPNS     | IPNE     | CY2 | CY3 | COUNTRY
19791872 | 19922943 | TH  | THA | THAILAND

フォームは、IP アドレスから IP 番号を計算し、それを という TextBox に配置しますIPNumber。これを SQL クエリで使用して、それに対応する国を取得します。

私の現在のクエリは次のとおりです。

SELECT IPLocation.IPNS, IPLocation.IPNE, IPLocation.CY2, IPLocationCY3, IP.Location.Country 
  FROM IPLocation 
 WHERE (((IPLocation.IPNS)<" & [Forms]![IP Country Form]![IPNumber]) 
   And ((IPLocation.IPNE) > " & [Forms]![IP Country Form]![IPNumber]))

IPNS、IPNE は、IPNumber と同様の数値です。

基本的に、クエリは、IPNumber が IPNS と IPNE の間にある国を見つけるように設計されています。

どんな助けでも大歓迎です。

私が使用するテストクエリ:

Set rst = dbs.OpenRecordset("
                 SELECT IPLocation.IPNS, IPLocation.IPNE, IPLocation.CY2, IPLocation.CY3,
                        IPLocation.Country 
                   FROM IPLocation 
                  WHERE (((IPLocation.IPNS)>19791871) 
                    AND ((IPLocation.IPNE)<19922944))
           ")

正常に動作し、正しい国を返します

4

1 に答える 1

0

ANDコードで使用するクエリでは、句で比較演算子が逆になっています。

IPLocation.IPNS) > " & [Forms]![IP Country Form]![IPNumber]

IPLocation.IPNE) < " & [Forms]![IP Country Form]![IPNumber]

次のようにする必要があります。

SELECT IPLocation.IPNS, IPLocation.IPNE, IPLocation.CY2, IPLocationCY3,
       IP.Location.Country 
  FROM IPLocation 
 WHERE (((IPLocation.IPNS) > " & [Forms]![IP Country Form]![IPNumber]) 
   And ((IPLocation.IPNE) < " & [Forms]![IP Country Form]![IPNumber]))
于 2012-09-21T08:31:30.320 に答える