Fix SQL for stock costs issue