declare @num int, @sqls nvarchar(4000) set @sqls='select @a=123 ' exec sp_executesql @sqls,N'@a int output',@num output select @num