尝试运行将结果插入到 sql 表中的查询时出现此错误。我将表名作为参数传递,如何将层次结构值赋予插入语句。
这是我的代码:
declare @pathhere hierarchyid
select @pathhere=Path from SectionDetails where Sectionid=@sectionid and SectionName=@sectionname and Batchid=@batchid and Deptid=@deptid and Schoolid=@schoolid
插入stmt:
set @sqlstmt = 'insert into '+@batch+'(StudentID, StudentName,SectionID,SectionName,BatchID,BatchName, DeptID,DeptName, SchoolID,Path)
values('''+@sectionid+''','''+@sectionname+''','''+@sectionid+''','''+@sectionname+''','''+@batchid+''','''+@batchname+''','''+ @deptid+''','''+@deptname+''', '''+@schoolid+''','+ CAST(@pathhere as hierarchyid)+')'
exec(@sqlstmt)
我在这一行出现错误:
'+ CAST(@pathhere as hierarchyid)+'
作为Invalid operator for data type. Operator equals add, type equals hierarchyid.
谁能帮我弄清楚如何传递层次结构值