日期:2014-05-18 浏览次数:20594 次
@StockCode nvarchar(50), @days int as select min(LowestPrice) from ( select top (@days) LowestPrice from Stocks where StockCode=@StockCode order by UpdateTime desc )t
--用动态sql Exec SP_EXECUTESQL @sql语句
------解决方案--------------------
declare @sql varchar(8000) set @sql='select min(LowestPrice) from ( select top '+ltrim(@days)+' LowestPrice from Stocks where StockCode=@StockCode order by UpdateTime desc )t ' exec (@sql)
------解决方案--------------------
--两个变量,都需要从外面传进去 declare @sql varchar(8000) set @sql='select min(LowestPrice) from ( select top '+ltrim(@days)+' LowestPrice from Stocks where StockCode='+@StockCode+' order by UpdateTime desc )t ' exec (@sql)
------解决方案--------------------
declare @sql nvarchar(max) set @sql=' select min(LowestPrice) from ( select top ('+@days+') LowestPrice from Stocks where StockCode='''+@StockCode+''' order by UpdateTime desc )t'
------解决方案--------------------
exec sp_executesql @sql
------解决方案--------------------
@StockCode nvarchar(50), @days int as declare @sql varchar(8000) set @sql='select min(LowestPrice) from ( select top '+ltrim(@days)+' LowestPrice from Stocks where StockCode='''+@StockCode+''' order by UpdateTime desc )t ' exec (@sql)