我写了下面的代码,并抛出“ mycursor附近的语法不正确”错误。谁能让我知道我在做什么错?
SELECT DISTINCT [FILE_NAME] INTO #TEMP FROM [dbo].[ABI_IND_STR_PLAN_DAILY] WHERE Year<>'Year';
DECLARE @var CHAR(20)
DECLARE @str VARCHAR(1000)
DECLARE myCursor CURSOR
FOR SELECT distinct [FILE_NAME] FROM #TEMP
--SET @str=''
OPEN myCursor
--'''+@var+''',
FETCH NEXT FROM myCursor INTO @var
WHILE @@FETCH_STATUS=0
BEGIN
SET @str=' INSERT INTO [dbo].[ABI_IND_STR_PLAN_DAILY] SELECT
* from [dbo].[ABI_IND_STR_PLAN_DAILY] WHERE FILE_NAME='+@var ---------------- Change GL Period Accordingly , for eg if it is JUN YTD then GL period '<=6' if only JUN MTD then GL Period = 6
FETCH NEXT FROM myCursor INTO @var
PRINT(@str)
EXEC(@str)
END
CLOSE myCursor
DEALLOCATE myCursor