sql exec sp_executesql执行动态语句
SET @VarSql = 'SELECT TOP 1 @Count=W_Count'+@i+',@Amount=W_Amount'+@i+',@AddCount=W_AddCount'+@i+',@AddAmount=W_AddAmount'+@i+',@DecCount=W_DecCount'+@i+' from #欠费 where P_PriceID=@P_PriceID'
exec sp_executesql @VarSql,N'@P_PriceID NUMERIC(18,0),@Count DECIMAL(18,2) output,@Amount DECIMAL(18,2) output,@AddCount DECIMAL(18,2) output,@AddAmount DECIMAL(18,2) output,@DecCount DECIMAL(18,2) output',@P_PriceID,@Count output,@Amount output,@AddCount output,@AddAmount output,@DecCount output