开发者

Error:insert hierarchy values using storedprocedure

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,开发者_Go百科 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


You're trying to create a string that can be executed as a statement. So you need to get your hierarchyid into nvarchar(max) instead.

try: @pathhere.ToString()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜