Link to home
Start Free TrialLog in
Avatar of fireblues
fireblues

asked on

Create Stored Procedure from a table and add an extra column using join

I have a table. I want to develop a report that requires an additional column in that table. The additional column comes from another table.
I am planning to create a stored procedure from that original table and then to add an extra column from the other table using join.
To be informed that the data is updated regularly so I cannot use SELECT INTO kind of query.
How can I do this?
Does any one have idea or better suggestion to accomplish this?
Thanks in advance.
Avatar of chaau
chaau
Flag of Australia image

in SQL Server you can make stored procedures act like Select statements. These stored procedures can be used when building reports. All you need to do is to make the last statement of the stored procedure the SELECT statement you wish to be used as your report. Like this:
CREATE PROCEDURE uspGetAllEmployees
AS
    SET NOCOUNT ON;
    SELECT e.LastName, e.FirstName, h.Department
    FROM vEmployeeDepartmentHistory h INNER JOIN Employee e ON e.EmployeeID = h.EmployeeID;
GO

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ValentinoV
ValentinoV
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fireblues
fireblues

ASKER

Thanks for guiding me the way for the solution.
I've requested that this question be closed as follows:

Accepted answer: 0 points for fireblues's comment #a39854353

for the following reason:

I solved it using different way.
In comment #a39854353 you stated the following: "Thanks for guiding me the way for the solution."  That's a strong indication that the earlier posts have helped you to get to your solution, even if you "solved it using different way".  So those posts should get accepted as solution, not your own comment.  For that reason I'll object once more... (previous objection was because you closed with a C-grade without any further interaction with us, read through the links posted by Netminder to get an understanding why that's not a good idea)
Since, I am new to this portal, I didn't know about the grades A, B and C.
Now that I have read, I know what they mean.
My apologies.
Of course the link helped me to go in certain direction.
I'll definitely reward points for that. :)
Thanks.