Updated sqlcmd to handle subqueries