SQL for #232

Still need to add if statements to check for null values.
Merge branch 'production' of https://github.com/eDiper/bids into production