Well its formatted just fine anyway
Might be because it has leading spaces - anything with 4, or more, spaces on the front of each line formats automatically.
Some suggestions
FROM Sales.SalesOrderDetail AS S1, Sales.SalesOrderDetail AS S2
ON S1.ProductID = S2.ProductID
I assume this should be
FROM Sales.SalesOrderDetail AS S1
JOIN Sales.SalesOrderDetail AS S2
ON S1.ProductID = S2.ProductID
ModifiedDate tests should be in a WHERE clause (you could put the S2 tests in the JOIN or the WHERE clause, personal preference - some people only put the KEY columns in the JOIN, some people put everything, and both of those groups probably do some-and-some at some point in their careers!
This works, but is generally seen as A Bad Idea (ask your SQL friends what they think, eh?!!)
The use of the DATEPART (or pretty much any other) function prevents the query from being SARGable. Whenever possible SQL will use an Index to get straight to the heart of a query, however if you use a Function like this then SQL will, instead, process every row to calculate the result of the function, instead of using the index (of course you might not actually have an index on this column ...)
Dates are a bit funny, particularly if they include a time component, so instead of BETWEEN we tend to use >= and < (and have an endpoint which is one-more-than-the-last-item), so something like this:
WHERE S1.ModifiedDate >= '20080601' AND S1.ModifiedDate < '20080701'
AND S2.ModifiedDate >= '20080701' AND S2.ModifiedDate < '20080801'
This is just an "efficiency and performance" tweak though.
I can see where you are going with this, but you can't do it in that way.
You can do
SELECT S1.ProductID, COUNT(S1.ProductID) AS Jun_Prods, Count(S2.ProductID) As Jul_Prods
but that will just give you the number of rows that have that ProductID - which will (I assume) just be the number of Order Rows. (You'll also need a GROUP BY clause, I'll come to that).
I expect what you actually want is the (total) Quantity Sold for each Product across all orders (in the relevant month), for that you need (I'm guessing hat the column, in [SalesOrderDetail], is called [Qty] - I don't have AdventureWorks installed in my database; when you figure out what the actual name is just change it in my code:)
SELECT S1.ProductID, SUM(S1.Qty) AS Jun_Prods, SUM(S2.Qty) As Jul_Prods
and you need to add a
GROUP BY S1.ProductID
this will cause all aggregate functions (SUM, COUNT etc.) to be specific to each value of S1.ProductID - and because we are JOINing S2 on S1.ProductID = S2.ProductID then, in effect, the GROUP BY is on both of those columns as they will match.
Lastly the original question is "but saw a decline", so having calculated the Total Qty for each ProductID in June and July you need to only include the ones which sold less in July. After the GROUP BY clause you can put a HAVING clause - that will operate on the values of the aggregate functions - so after the data has been retrieved and prep'd up ready to display
HAVING SUM(S1.Qty) > SUM(S2.Qty)
There is a further wrinkle ... what if a ProductID that sold in June did not sell anything in July? I would consider that a "decline". Because your query uses a JOIN and WHERE clause then only ProductID which sold in BOTH June AND July will be included. You will need to use an OUTER JOIN to include ALL ProductID from June regardless of whether they sold in July. Also, doing SUM(S2.Qty) for July will give you warnings when no value exists, and
HAVING SUM(S1.Qty) > SUM(S2.Qty)
will NOT consider that a missing (NULL) value for SUM(S2.Qty) is less than SUM(S1.Qty) - NULL compared to anything is always FALSE.
We can help with that OUTER JOIN edge-condition once you've got the main query working. I've not given you a Cut & Paste fully-finished answer, deliberately :), but hopefully enough that you will get there on your own ... but if you get stuck post your work so far and any error message, or incorrect results values (and the values you actually expect to see) and someone here will nudge you in the right direction.