MapInfo Pro Developers User Group

Welcome to the MapInfo Pro Developers community!  We are a group dedicated to the discussion and understanding of MapBasic and .Net MapInfoPro AddIn development. Bring your questions and ideas here. This group includes several members of the Pro development team from around the world.

Please feel free to start a discussion in the discussion tab or join in a conversation.

Product Information  Ideas Portal  MapInfo Community Downloads

Discussions

Members

Resources

Events

 View Only
  • 1.  SQL statement for selecting 50 values from the same column

    Posted 04-11-2018 07:50

    When I need to run an SQL Select using a Where condition that has say 50 records all from the same column in a table, is there a way to do this without having to repeat the column label for every record?

    For example:

    T1_AssetNo = "44588" Or T1_AssetNo = "44591" Or T1_AssetNo = "44592" Or T1_AssetNo = "44954" Or T1_AssetNo = "44595" Or T1_AssetNo = "44596" Or T1_AssetNo = "44597" Or T1_AssetNo = "44598" Or T1_AssetNo = "44599" Or T1_AssetNo = "44600" Or T1_AssetNo = "44601" Or T1_AssetNo = "44602" Or T1_AssetNo = "44603" Or T1_AssetNo = "44604" Or T1_AssetNo = "44605" Or T1_AssetNo = "44606" Or T1_AssetNo = "44607" Or T1_AssetNo = "44608" Or T1_AssetNo = "44609" Or T1_AssetNo ="44611" Or T1_AssetNo = "44612" Or T1_AssetNo = "44613"

    I tried leaving out the T1_AssetNo field and it selected all records in the table. I tried other variations of the syntax but received errors.



  • 2.  RE: SQL statement for selecting 50 values from the same column

    Posted 04-11-2018 03:56

    Oops...forgot to take out the " "?  before I posted : )



  • 3.  RE: SQL statement for selecting 50 values from the same column

    Employee
    Posted 04-11-2018 04:17

    Hi Angelene,

    If your T1_AssetNo field is a numerical field and the group of records which you wish to select are within a certain range of numbers then you could consider trying the following syntax:

    T1_Asset > XXX1 and Name < XXX2

     

    (where XXX1 is lower range threshold number and XXX2 is higher range threshold number)



  • 4.  RE: SQL statement for selecting 50 values from the same column

    Posted 04-11-2018 05:33

    If the field is a string, rather than numeric, then you could try:

    select * from tablename where T1_AssetNo = any ("44954","44595","44596","44597","44598","44599","44600","44601","44602","44603","44604","44605","44606","44607","44608","44609","44611","44612","44613")

    or depending on the asset number range, you could use a wildcard:

    select * from tablename where T1_AssetNo like "4459%" OR T1_AssetNo like "460%"

     

    Greg



  • 5.  RE: SQL statement for selecting 50 values from the same column

    Posted 04-11-2018 18:36

    Thanks for the replies Dave & Greg!?