I need assistance with a SQL Server Query

Posted on 2011-10-05
Last Modified: 2012-05-12
Hi Experts,
I want to create a StoredProc That takes the results of a StoredProc and then I append two columns from a table.  For example:

The original StoredProc returns a students First Name and Last Name, but I also want to display the students teacher's name which

lives in table tblTeacher.  Both the Stored Proc and tblTeacher are linked by the StudentID column.  

Can this be done?  If so, how?

Thanks in advance,
Question by:mainrotor
    LVL 18

    Accepted Solution

    You can use and INSERT-EXECUTE to add the values from the first proc into a temp table

    CReATE TABLE #DEMO  (add your colums)

    EXECUTE proc

    SELECT *
    JOIN OtherTable OTHER


    LVL 21

    Assisted Solution

    In the new procedure, I would insert the results of the stored procedure that returns the student name into a temp table or table variable.  Then you could join it to the students table based on the first and last name and then join to tblTeacher.  

    That being said, why do you want to call the other stored procedure?  It seems like you could do this in a single query without jumping through all of these hoops.  


    LVL 67

    Expert Comment

    I've requested that this question be deleted for the following reason:

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
    LVL 18

    Expert Comment

    2 experts spent time and effort to suggest solutions.  Why don't we get any credit?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now