Few days ago I faced following challenge. SQL profiler gave me ugly SQL, which was unreadable for my eyes.
For example like this:
exec sp_executesql N'SELECT APAddress.AddressID, APAddress.VendorID, APAddress.VendorAddressID, APAddress.IsDefaultAddress, APAddress.RevisionID, APAddress.AddressLine1, APAddress.AddressLine2, APAddress.AddressLine3, APAddress.City, APAddress.CountryID, APAddress.State, APAddress.PostalCode, APAddress.IsValidated, APAddress.tstamp, APAddress.CreatedByID, APAddress.CreatedByScreenID, APAddress.CreatedDateTime, APAddress.LastModifiedByID, APAddress.LastModifiedByScreenID, APAddress.LastModifiedDateTime FROM APAddress APAddress WHERE (APAddress.CompanyID = 2) AND ( APAddress.AddressID = @P0) ORDER BY APAddress.AddressID /* admin@AP.30.40.00 */',N'@P0 int',@P0=-2147483647
If you can read it, congratulations, you are genius and I'm envy of you so you can stop reading further. But if you are just programmer as me, then the next step is the following:
1. remove exec sp_executesql
2. In some editor find and replace @P0 with value -2147483647
3. remove tail /* admin@AP.30.40.00 */',N'@P0 int',@P0=-2147483647
4. Navigate in your browser to http://www.dpriver.com/pp/sqlformat.htm
5. Copy/Paste in window and choose format mssql
6. Press format SQL.
Compare previous sql with the following:
FROM apaddress APAddress
WHERE ( apaddress.companyid = 2 )
AND ( apaddress.addressid = -2147483647 )
ORDER BY apaddress.addressid
IMHO the second option is easier to read.