As Sean said, there are better ways to do it than a cursor. Here's an option using XML PATH which is explained in the following article: http://www.sqlservercentral.com/articles/comma+separated+list/71700/
To solve your problem, have you considered using a global temp table (##Table)?
DECLARE @firstSQL VARCHAR(max)
SET @firstSQL = 'SELECT Site, [Family ID], [First Name], [Last Name], [Survey Status], [Date Started], [Date Completed], '
', [' + cf.sourceSystemFieldID + '] AS ' + ISNULL(NULLIF( tf.preferredFieldName, 'NULL'), 'EDIT')
FROM [itmidw].[tblCrfTranslationField] tf
JOIN itmidw.tblCrfFields cf ON tf.fieldID = cf.fieldID
WHERE crfVersionName = '6MonthBaby: v1'
FOR XML PATH('')) --Change HERE
+ ' INTO ##AGlobalTempTable'
+ ' FROM etl.SurveyBaby6_Stage'
Luis C.General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?How to post data/code on a forum to get the best help: Option 1 / Option 2