INSERT SELECT with Stored Procedures?

J

John Bailo

A cool feature of SQL is that I can use a SELECT statement and pass
values into an INSERT -- great for moving a few records between tables.

Question, is there a way to use a SELECT to pass values into a stored
procedure?
 
G

Garfilone

ye,of cource you can do that

sample SP shows as below:

CREATE PROCEDURE ShowAFile
@FileNo nvarchar(50)
as
select c.FileNO,
c.Name,
c.Sex ,
c.Birthday,
e.RaceName,
c.Political,
c.PriQualify,
c.PriGradSchool,
c.PriGradDate,
c.Qualify,
c.GradSchool,
c.GradDate,
b.DutyName ,
f.TitleName,
d.JobName,
a.DeptName,
c.WorkDate,
c.EnterDate,
c.OrgDateé—´,
c.Origin,
c.Resume
from Departments a,Duties b,Files c,Jobs d,Races e,Titles f
where a.DeptID=c.DeptID and b.DutyID=c.DutyID and d.JobID=c.JobID and
e.RaceID=c.RaceID
and f.TitleID=c.TitleID
and c.FileNo=@FileNo
GO
 
C

Chris Dunaway

Garfilone said:
ye,of cource you can do that

sample SP shows as below:

<snip>

That's not what he asked. He wants the result set from the Select
statement to be passed INTO the stored procedure. In SQL you can do
this:

INSERT Into tablename SELECT * From whatever

This uses the results of the select as the field values for the insert.
I believe the OP wants to do a similar action using a stored procedure
instead of an insert statement:

Something like this (pseudocode to illustrate point):

EXEC spStoredProcName SELECT * From Whatever

Which is not possible AFAIK.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top