请高手帮忙看下,下面这段代码怎么老是报如下错误:服务器: 消息 214,级别 16,状态 2,过程 sp_executesql,行 28
过程需要参数 '@statement' 为 'ntext/nchar/nvarchar' 类型。
DECLARE @Flow_Code  INT--=================================
SET @Flow_Code=7
---================================DECLARE @TableName VARCHAR(100)
DECLARE @User_Code INT
DECLARE @User_Name VARCHAR(100)
DECLARE @COUNT INT
DECLARE @SQL VARCHAR(1000)
set @TableName=''
select @TableName=Table_Name from M_Flow_Info where Flow_Code=@Flow_Code
SET @TableName='u_'+@TableName--CREATE TABLE #list([Name] VARCHAR(100),MyCount INT,Other INT) --定义临时表--定义游标
DECLARE change_contract_M_Flow_Info CURSOR FOR SELECT User_code,[User_Name]  from M_User_Info WHERE User_IsOut=0  
--打开游标
OPEN change_contract_M_Flow_Info
FETCH NEXT FROM change_contract_M_Flow_Info INTO @User_Code,@User_Name
WHILE @@fetch_status = 0
BEGIN
set @SQL=N'select @COUNT=count(c.instance_id) from (select a.instance_id from '''+@TableName+''' a inner join  
(SELECT instance_id FROM T_Node_Info WHERE Flow_Code = '+ltrim(@Flow_Code)+' AND User_Code = '+ltrim(@User_Code)+' AND Accept_Date <> '' AND Exit_Date IS NULL and  Status_Code<>3) b 
on a.instance_id=b.instance_id) c' 
Exec sp_executesql @SQL,N'@COUNT int output',@COUNT output
INSERT INTO #list([Name],MyCount,Other)VALUES(@User_Name,@COUNT,0)
   FETCH NEXT FROM change_contract_M_Flow_Info INTO @User_Code,@User_Name
ENDCLOSE change_contract_M_Flow_Info 
DEALLOCATE change_contract_M_Flow_InfoSELECT * FROM #list