
#Excel replace carriage return with space code
Obviously you can *NOT* simply copy the "repaired" text into a query window and hit execute - if nothing else this method breaks inline comments which makes the code unexecutable. This "repaired" text is easily paste-able into Excel into a single column, giving us an easily manageable spreadsheet. SELECT FROM ( SELECT DISTINCT ma.Material_Attachment_ID FROM Topic_Main tm WITH (NOLOCK) INNER JOIN Material_Topic mt WITH (NOLOCK) ON tm.Topic_ID=mt.Topic_ID INNER JOIN Material_Attachment ma WITH (NOLOCK) ON mt.Material_id=ma.Material_id WHERE tm.Invisible_Flag=0 AND AND tm.Topic_ID IN (SELECT CountReturned FROM #CountResults)) AS que INNER JOIN Download_All_Distinct dad WITH (NOLOCK) ON que.Material_Attachment_ID= dad.Material_Attachment_ID WHERE dad.Download_Date >=DATEADD(year, -1, GETDATE()) ->Query to calculate Experts based on Topic ID (PA) >Query to calculate Experts based on Topic ID (PA)

WHERE dad.Download_Date >=DATEADD(year, -1, GETDATE()) INNER JOIN Download_All_Distinct dad WITH (NOLOCK) ON que.Material_Attachment_ID=dad.Material_Attachment_ID WHERE tm.Invisible_Flag=0 AND AND tm.Topic_ID IN (SELECT CountReturned FROM #CountResults)) AS que INNER JOIN Material_Attachment ma WITH (NOLOCK) ON mt.Material_id=ma.Material_id INNER JOIN Material_Topic mt WITH (NOLOCK) ON tm.Topic_ID=mt.Topic_ID SELECT DISTINCT ma.Material_Attachment_ID , ' ', ' ') /* Change Two Spaces to Space */

To fix this last piece, let's try one more REPLACE to remove double spaces for single spaces: Note that for some code, this may be the extent of what you need - you may not have all of that ugly whitespace. SELECT FROM ( SELECT DISTINCT ma.Material_Attachment_ID FROM Topic_Main tm WITH (NOLOCK) INNER JOIN Material_Topic mt WITH (NOLOCK) ON tm.Topic_ID=mt.Topic_ID INNER JOIN Material_Attachment ma WITH (NOLOCK) ON mt.Material_id=ma.Material_id WHERE tm.Invisible_Flag=0 AND AND tm.Topic_ID IN (SELECT CountReturned FROM #CountResults)) AS que INNER JOIN Download_All_Distinct dad WITH (NOLOCK) ON que.Material_Attachment_ID=dad.Material_Attachment_ID WHERE dad.Download_Date >=DATEADD(year, -1, GETDATE()) ->Query to calculate Experts based on Topic ID (PA) , CHAR(10), ' ') /* Change LF to Space */ , CHAR(13), ' ' ) /* Change CR to Space */
