Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

sql - SQL Server - SELECT FROM存储过程(SQL Server - SELECT FROM stored procedure)

I have a stored procedure that returns rows:

(我有一个返回行的存储过程:)

CREATE PROCEDURE MyProc
AS
BEGIN
    SELECT * FROM MyTable
END

My actual procedure is a little more complicated, which is why a sproc is necessary.

(我的实际程序有点复杂,这就是为什么有必要使用sproc的原因。)

Is it possible to select the output by calling this procedure?

(是否可以通过调用此过程来选择输出?)

Something like:

(就像是:)

SELECT * FROM (EXEC MyProc) AS TEMP

I need to use SELECT TOP X , ROW_NUMBER , and an additional WHERE clause to page my data, and I don't really want to pass these values as parameters.

(我需要使用SELECT TOP XROW_NUMBER和一个额外的WHERE子句来分页我的数据,我真的不想将这些值作为参数传递。)

  ask by jonathanpeppers translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can

(您可以)

  1. create a table variable to hold the result set from the stored proc and then

    (创建一个表变量来保存存储过程中的结果集然后)

  2. insert the output of the stored proc into the table variable, and then

    (将存储过程的输出插入表变量,然后)

  3. use the table variable exactly as you would any other table...

    (完全像使用任何其他表一样使用表变量...)

... sql ....

(...... sql ....)

Declare @T Table ([column definitions here])
Insert @T Exec storedProcname params 
Select * from @T Where ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...