CAST in sql, needs more work