title: How to call different tables in an "if and else" part of the same database in iPhone?
body: <p>I have a database. It has two tables in it. I want to call one table in an <code>if</code> condition.  How do I call the second table in the <code>else</code> part if the <code>if</code> conditions fail?</p>
  
  <p>This is the code I used:</p>
  
  <pre><code>{
      NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *DocumentsDirectory = [Paths objectAtIndex:0];
      NSString *Path = [DocumentsDirectory stringByAppendingPathComponent:@"StoreList.sqlite"];
  
      // Open the database from the users filessytem.
      if (sqlite3_open([Path UTF8String], &amp;database) == SQLITE_OK) {
          // Setup the SQL Statement and compile it for faster access
          //*********const char *sqlStatement = "select * from Store where Zipcode ='%@'",inputTxt ;
  
          NSString *sqlStatement = [NSString stringWithFormat:@"select * from Store where Zipcode ='%@' or Address = '%@' or CityName = '%@'",inputTxt, inputTxt, inputTxt];
          NSLog(@" Query in if :%@",sqlStatement);
          sqlite3_stmt *compiledStatement;
  
          if (sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &amp;compiledStatement, NULL) == SQLITE_OK) {
  
              // Loop through the results and add them to the feeds array.
  
              if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                  // Read the data from the result row
  
                  NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
                  NSLog(@"Latitude:%@",latValue);
                  NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
                  NSLog(@"Longitude:%@",longValue);
                  //currentLocationLbl.text=[NSString stringWithFormat:@" %@ , %@" ,latValue,longValue];
  
                  // delegate.latitudeVal=latValue;
                  // delegate.longitudeVal=longValue;
                  txtChangeLocation.text = @"";
                  isFromChangeLoc=TRUE;
  
                  //self.tabBarController.selectedIndex=3;
              }
              else {
                  NSLog(@"ELSE PART");
  
                  // Open the database from the user's filessytem.
                  if (sqlite3_open([Path UTF8String], &amp;database) == SQLITE_OK) {
                      // Setup the SQL Statement and compile it for faster access
                      //*********const char *sqlStatement = "select * from Store where Zipcode ='%@'",inputTxt ;
  
                      NSString *sqlStatement = [NSString stringWithFormat:@"select * from zipcodes where zip ='35004'"];
                      NSLog(@" Query in if :%@",sqlStatement);
                      sqlite3_stmt *compiledStatement;
  
                      if(sqlite3_prepare_v2(database, [sqlStatement UTF8String], -1, &amp;compiledStatement, NULL) == SQLITE_OK) {
                          // Loop through the results and add them to the feeds array
  
                          if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
                              // Read the data from the result row
  
                              NSString *latValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
                              NSLog(@"Latitude:%@",latValue);
                              NSString *longValue = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
                              NSLog(@"Longitude:%@",longValue);
                              //currentLocationLbl.text=[NSString stringWithFormat:@" %@ , %@" ,latValue,longValue];
  
                              // delegate.latitudeVal=latValue;
                              // delegate.longitudeVal=longValue;
                              txtChangeLocation.text = @"";
                              isFromChangeLoc=TRUE;
                          }
                      }
                  }
              }
              sqlite3_finalize(compiledStatement);
              sqlite3_close(database);
          }
      }
  </code></pre>
  
  <p>I'm getting the input from the text box. When I give the correct value, which is there in the database, it is working fine, the fetch of the data is correct. If I give the wrong data in the textbox it's not working fine - the <code>else</code> condition fails.</p>
  
  <p>How can this issue be fixed?</p>