寫了個存儲過程是這樣的
create proc [dbo].[GetHotKeys]
(
@top int,
@where nvarchar(1000)
)
as
declare @sqlStr nvarchar(1000)
if @top<>''
set @sqlStr='select top '+cast(@top as varchar(10))+' * from hotkeys '+@where
else
set @sqlStr='select * from hotkeys '+@where
結果出現錯誤:在將 varchar 值 'select top ' 轉換成數據類型 int 時失敗。
解決辦法:set @sqlStr='select top '+cast(@top as varchar(10))+' * from hotkeys '+@where
ok