I always use the following script and it works great. After the script finishes and the logfile is still bigger then you want, just run it again for a couple...
Within a stored procedure you can also store the results of the complex query in a temporary table (e.g. SELECT INTO #complextable) and then use the self-join on the temporary...