A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Can you show us your data structure? Either as a sketch or as a DDL or screenshots?1
Without any information on your environment, your system, and your "data layout," we cannot give you any (working) advice.
Maybe it is just a simple "JOIN," or it can be a complex workflow...