I'm getting this error when trying to run a query that inserts results into a table in sql. im passing the table name as parameter,how to give the hierarchy value to the insert statement.
here is my code:
declare @pathhere hierarchyid
select @pathhere=Path from SectionDetails where Sectionid=@sectionid and SectionName=@sectionname and Batchid=@batchid and Deptid=@deptid and Schoolid=@schoolid
insert 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)
im getting error in this line:
'+ CAST(@pathhere as hierarchyid)+'
as Invalid operator for data type. Operator equals add, type equals hierarchyid.
can anyone pls help me out how to pass the hierarchy value