Hi
I have a cursor that is not working it seems to work up until it goes to insert the first record in the table. The cursor loops through a list of table names and then for each table that is inserts into a table it adds the stuff in thee the dynamic SQL So I am thinking that the syntax is wrong.
Can someone tell me is this is right?
OPEN x
FETCH NEXT FROM x INTO @tableTH
PRINT 'I am in place 1'
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT N'Processing table ' + LTRIM(RTRIM( @tableTH))
PRINT 'I am in place 2'
SET @SQL = 'select ''' + @tableTH + '''
, ''' + @tableTH + '''
,ISNULL((select top 1 1 from ' + @tableTH + ' group by file_no having count(file_no) > 0) ,0)
,ISNULL((select top 1 0 from ' + @tableTH + ' group by file_no having count(file_no) > 1) ,1)
,''xx''
,10
,10
,15
,5
,0
,0
,0
,0
,0
,0
,1
'
PRINT 'I am in place 3'
PRINT @SQL
INSERT INTO [DMPCRU].[dbo].[TableHelper] EXECUTE (@SQL)
PRINT 'I am in place 4'
--EXEC (@SQL)
FETCH NEXT FROM x INTO @tableTH
END
CLOSE x
DEALLOCATE x