Code: Select all
Create TABLE #TABLE_ID# AS ...
Code: Select all
Create TABLE #TABLE_ID# SELECT * FROM [Second Table]
Here is the full code of my procedure
*note i'm working off of existing data that was poorly built 20 years ago in Access I've modified some of the column and table names so I don't have #'s and /'s all over my column and table names*
Code: Select all
$a = "DROP TABLE IF EXISTS DataForRptAllUnitsMasterListSub1;";
nuRunQuery ($a);
$b = "SELECT
tblCurrentRentedUnits.UnitNumber,
CONCAT(IF(tblTenants.BusinessName != '', tblTenants.BusinessName,''), IF(tblTenants.BusinessName != '' AND tblTenants.LastName != '', ' - ', ''), IF(tblTenants.LastName != '', tblTenants.LastName, ''), IF(tblTenants.LastName != '' AND tblTenants.FirstName != '', ', ', ''), IF(tblTenants.FirstName != '', tblTenants.FirstName, '')) AS FullName,
tblTenants.TenantID,
tblCurrentRentedUnits.MoveInDate,
tblCurrentRentedUnits.Rate,
tblTenants.HomePhone,
tblTenants.BusPhone
FROM
tblCurrentRentedUnits
JOIN tblTenants ON tblCurrentRentedUnits.AssocTenantID = tblTenants.TenantID
WHERE
tblCurrentRentedUnits.Vacated = False
ORDER BY
tblCurrentRentedUnits.UnitNumber ASC;";
nuRunQuery ("CREATE TABLE DataForRptAllUnitsMasterListSub1 AS $b;");
$c = "DROP TABLE IF EXISTS DataForRptMasterListOneLocation;";
nuRunQuery ($c);
$d = "CREATE TABLE DataForRptMasterListOneLocation AS SELECT
tblUnits.UnitID,
IF(DataForRptAllUnitsMasterListSub1.TenantID IS NULL, 'VACANT', 'Rented') AS UnitCondition,
tblUnits.Location,
tblUnits.Size,
IF(DataForRptAllUnitsMasterListSub1.TenantID IS NULL, '', DataForRptAllUnitsMasterListSub1.FullName) AS RentedBy,
DataForRptAllUnitsMasterListSub1.HomePhone,
DataForRptAllUnitsMasterListSub1.BusPhone,
DataForRptAllUnitsMasterListSub1.MoveInDate,
DataForRptAllUnitsMasterListSub1.Rate,
tblUnits.UnitSort
FROM
tblUnits
LEFT JOIN DataForRptAllUnitsMasterListSub1 ON tblUnits.UnitID = DataForRptAllUnitsMasterListSub1.UnitNumber
INNER JOIN tblLocationToUse ON tblUnits.Location = tblLocationToUse.Location
ORDER BY
tblUnits.UnitSort;";
nuRunQuery($d);
$e = "Create TABLE #TABLE_ID# AS SELECT * FROM DataForRptMasterListOneLocation";
nuRunQuery($e);