public static function getJoinQuery($sids, $cols, $perPage, $pageNo)
 {
     global $db;
     $finalQuery = "";
     $finalQueryJoinWherePart = "";
     if (count($sids) == 1) {
         $sid = UtilsForWizard::getWordUntilFirstDot($sids[0]);
         $tableName = UtilsForWizard::stripWordUntilFirstDot($sids[0]);
         $sourceType = ExternalMSSQL::GetSourceType($sid);
         if ($sourceType == "data file") {
             return ExternalMSSQL::wrapInLimit($pageNo, $perPage, $tableName);
         } else {
             $colsString = "'" . implode("','", $cols) . "'";
             $query = ExternalMSSQL::makeQueryToRotateTable($sid, $tableName, $colsString);
             $finalQuery = $query;
             return ExternalMSSQL::wrapInLimit($pageNo, $perPage, "(" . $finalQuery . ") as b");
         }
     } else {
         for ($i = 0; $i < count($sids) - 1; $i++) {
             $sidFrom = UtilsForWizard::getWordUntilFirstDot($sids[$i]);
             $tableNameFrom = UtilsForWizard::stripWordUntilFirstDot($sids[$i]);
             $sourceTypeFrom = ExternalMSSQL::GetSourceType($sidFrom);
             if ($sourceTypeFrom == "data file") {
                 $colsResult = ExternalMSSQL::getAllTableNameDotColumnsBySid($sidFrom, $tableNameFrom);
                 $colsRenamed = $colsResult->colsRenamed;
                 $finalQuery .= "(select {$colsRenamed} from {$tableNameFrom}) as rot{$i}, ";
             } else {
                 $colsString = "'" . implode("','", $cols) . "'";
                 $query = ExternalMSSQL::makeQueryToRotateTable($sidFrom, $tableNameFrom, $colsString, $perPage, $pageNo);
                 $finalQuery .= "({$query}) as rot{$i}, ";
             }
             $sidTo = UtilsForWizard::getWordUntilFirstDot($sids[$i + 1]);
             $tableNameTo = UtilsForWizard::stripWordUntilFirstDot($sids[$i + 1]);
             $sourceTypeTo = ExternalMSSQL::GetSourceType($sidTo);
             $finalQueryJoinWherePart .= ExternalMSSQL::getWhereJoinPart($i, $sidFrom, $tableNameFrom, $sidTo, $tableNameTo, $sourceTypeFrom, $sourceTypeTo);
         }
         $sidFrom = UtilsForWizard::getWordUntilFirstDot($sids[count($sids) - 1]);
         $tableNameFrom = UtilsForWizard::stripWordUntilFirstDot($sids[count($sids) - 1]);
         $sourceType = ExternalMSSQL::GetSourceType($sidFrom);
         if ($sourceType == "data file") {
             $colsResult = ExternalMSSQL::getAllTableNameDotColumnsBySid($sidFrom, $tableNameFrom);
             $colsRenamed = $colsResult->colsRenamed;
             $finalQuery .= "(select {$colsRenamed} from {$tableNameFrom}) as rot" . (count($sids) - 1);
         } else {
             $colsString = "'" . implode("','", $cols) . "'";
             $query = ExternalMSSQL::makeQueryToRotateTable($sidFrom, $tableNameFrom, $colsString, $perPage, $pageNo);
             $finalQuery .= "({$query}) as rot" . (count($sids) - 1);
         }
         if ($finalQueryJoinWherePart != "") {
             $finalQueryJoinWherePart = substr($finalQueryJoinWherePart, 0, -4);
         }
         $finalQuery = "select * from {$finalQuery} where {$finalQueryJoinWherePart}";
         return ExternalMSSQL::wrapInLimit($pageNo, $perPage, "(" . $finalQuery . ") as b");
     }
 }
 static function processOneColumn($sid, $originalDname, $newDname, $type, $unit, $description, $metadata, $tableName = null, $constantValue, $missingValue)
 {
     //var_dump($sid, $originalDname, $newDname, $type, $unit, $description, $metadata, $tableName, $missingValue);
     $queryEngine = new QueryEngine();
     if (!isset($tableName)) {
         $tableName = UtilsForWizard::getWordUntilFirstDot($originalDname);
     }
     $originalDnameStripped = str_replace($tableName . '.', '', $originalDname);
     $cid = $queryEngine->simpleQuery->addColumnInfo($sid, $newDname, $type, $unit, $description, $originalDnameStripped, $constantValue, $missingValue);
     $queryEngine->simpleQuery->addColumnTableInfo($cid, $tableName);
     if (!($metadata === NULL)) {
         foreach ($metadata as $value2) {
             $queryEngine->simpleQuery->addColumnDataMatchingInfo($sid, $cid, $value2["category"], $value2["suggestedValue"]);
         }
     }
 }