开发者

SQL Select SUM(col) from exec stored_proc?

开发者 https://www.devze.com 2023-04-13 09:25 出处:网络
Is there an easy way in SQL Server (2010) to exec a stored procedure (that returns a table) and sum a column in one (or a few) statements?

Is there an easy way in SQL Server (2010) to exec a stored procedure (that returns a table) and sum a column in one (or a few) statements?

eg

SELECT SU开发者_如何学GoM(column) FROM exec proc_GetSomeStuff 'param1', 'param2'


Don't have a server handy to test with, but try this:

declare @temp table(col1 int)

insert into @temp(col1)
exec proc_GetSomeStuff 'param1', 'param2'

select sum(col1) from @temp

Make sure your table variable (or temp table) has the same schema as the results of the stored procedure. If you know that there will be a significant number of rows coming back from the SP, then a temporary table might be a better option. (I'm not sure if table variables can be flushed out to disk if they get too big)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号