Professional Documents
Culture Documents
*/
SELECT*
FROM Practice.dbo.NashvilleHousing
UPDATE Practice.dbo.NashvilleHousing
SET SaleDateConverted = CONVERT(DATE,SaleDate);
SELECT SaleDateConverted
FROM Practice.dbo.NashvilleHousing
SELECT PropertyAddress
FROM Practice.dbo.NashvilleHousing
WHERE PropertyAddress IS NULL
SELECT*
FROM Practice.dbo.NashvilleHousing
ORDER BY ParcelID
SELECT a.ParcelID, a.PropertyAddress, b.ParcelID, b.PropertyAddress,
ISNULL(a.PropertyAddress, b.PropertyAddress)
FROM Practice.dbo.NashvilleHousing AS a
JOIN Practice.dbo.NashvilleHousing AS b
on a.ParcelID = b.ParcelID
AND a.[UniqueID] <> b.[UniqueID]
WHERE a.PropertyAddress IS NULL
UPDATE a
SET PropertyAddress = ISNULL(a.PropertyAddress, b.PropertyAddress)
FROM Practice.dbo.NashvilleHousing AS a
JOIN Practice.dbo.NashvilleHousing AS b
on a.ParcelID = b.ParcelID
AND a.[UniqueID] <> b.[UniqueID]
WHERE a.PropertyAddress IS NULL
/*Part 3 - Separating Address attributes into individual Collumns (Address, City, State) */
SELECT PropertyAddress
FROM Practice.dbo.NashvilleHousing
/* 1st Substring starts from position 1 all the way to ",", basically specify that I want everything
until the comma but not the comma 8(thus the -1)
2nd Substring starts from the "," all the way to the end, but because address may have more
or less characters, LEN(PropertyAddress) is used to fix that.
The "+1" also indicate to start after the ",".
*/
UPDATE Practice.dbo.NashvilleHousing
SET PropertySplitAddress = SUBSTRING(PropertyAddress, 1, CHARINDEX(',',
PropertyAddress)-1);
UPDATE Practice.dbo.NashvilleHousing
SET PropertySplitCity = SUBSTRING(PropertyAddress, CHARINDEX(',', PropertyAddress)+1,
LEN(PropertyAddress));
SELECT*
FROM Practice.dbo.NashvilleHousing
/--Side note: Parsing could also be done on this instance and the alter and update like before
Select
PARSENAME(REPLACE(OwnerAddress,',','.'),3) AS "Address",
PARSENAME(REPLACE(OwnerAddress,',','.'),2) AS "City",
PARSENAME(REPLACE(OwnerAddress,',','.'),1) AS "State"
FROM Practice.dbo.NashvilleHousing
SELECT SoldAsVacant,
CASE WHEN SoldAsVacant = 'Y' THEN 'Yes' WHEN SoldAsVacant = 'N' THEN 'No'
ElSE SoldAsVacant END
FROM Practice.dbo.NashvilleHousing
UPDATE Practice.dbo.NashvilleHousing
SET SoldAsVacant = CASE WHEN SoldAsVacant = 'Y' THEN 'Yes' WHEN SoldAsVacant = 'N'
THEN 'No' ElSE SoldAsVacant END
/*Remove Duplicates for the whole spreadsheet (in this case I will
actually delete the data without creating a
backup since this is just a training set)*/
-- The CTE common table expression is going to be used to define the query block, so it can be
used again
-- Deleting duplicates
-- Delete unused Columns (again this is a dataset used for training so its ok to delete)
SELECT*
FROM Practice.dbo.NashvilleHousing