1

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.

誰かplsが階層値を渡す方法を教えてくれますか

4

1 に答える 1

0

ステートメントとして実行できる文字列を作成しようとしています。したがって、代わりに、hierarchyidをnvarchar(max)に入れる必要があります。

試す: @pathhere.ToString()

于 2010-01-27T05:15:08.020 に答える