Your original requirement was a T-SQL query which, if I understand correctly, isn't going to work against an Oracle database. You'll need to go to an Oracle forum to get help on that. There may be a way of writing code that works on both Oracle and SQL Server.
John