私はこの質問をオンラインでグーグルで検索しましたが、これがエラーをスローし続けた理由を私が一生理解できなかったので、助けていただければ幸いです。
nvarchar値の変換時に変換に失敗しました'SELECT@orderid = t.orderid FROM(SELECT *、ROW_NUMBER()OVER(PARTITION BY id ORDER BY Creationdatetime DESC)AS rowFROM[intranet]。[dbo].handbook_appendix_dataWHERE id ='toデータ型int。
DECLARE @sql nvarchar(500)
DECLARE @table varchar(40)
SET @table = 'handbook_section_data';
SET @table = 'handbook_appendix_data';
DECLARE @parentid INT
DECLARE @id INT
DECLARE @published INT
DECLARE @orderid INT
SET @parentid = 2
SET @id = -1
SET @published = 1
SET @sql = N'SELECT @orderid = t.orderid FROM
(SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY creationdatetime DESC) AS row FROM [intranet].[dbo].'+@table+' WHERE id = '+@id+' AND published = '+@published+') AS t
WHERE t.published = '+@published+' AND t.row = 1';
EXEC SP_EXECUTESQL @sql, N'@orderid INT OUTPUT', @orderid = @orderid OUTPUT --Get the OrderID from ID
PRINT @orderid