RE: Stored Procedure as part of SELECT?
From: Ben (Ben_at_discussions.microsoft.com)
Date: 12/06/04
- Next message: MGFoster: "Re: bit-wise and"
- Previous message: Ben: "RE: converting to sp_executesql"
- In reply to: Joe Williams: "Stored Procedure as part of SELECT?"
- Next in thread: Michael C: "Re: Stored Procedure as part of SELECT?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 6 Dec 2004 14:25:03 -0800
Joe,
I have found that using an UDF works really nice some times in place of a
view or a stored procedure. The UDF allows me to provide parameters and still
be able to join the results as in a view or table. This method allows me to
encapsulate the criteria for the query.
If your stored procedure is not too complicated take a look at turning it
into a view.
I have some situations where the queries are soooo complicated that I have
used multiple UDFs to break it up just so that I did not (I was not able to)
use a stored procedure.
Be careful with UDFs though...there are a lot of notes regarding performance
metrics not being reliable for queries that use an UDF. Your final option
that has not already been provided would be to turn the stored procedure into
a view. This often can not be done.
Cheers,
Ben
"Joe Williams" wrote:
> I have a Store Procedure that returns records based on parameters that I
> send it (date range). Then I also have two different views that return
> records. How do I create a new Stored Procedure that puts information from
> all three objects into one recordset?
>
> Example
>
> sp_EmployeeHours is a stored procedure that has two fields (EmployeeID,
> Sum(Hours) as WorkTotal) and the results are limited to data range critiera
> that I send to the stored procedure.
>
> vw_Employee is a view and has fields like (EmployeeID, FirstName, LastName)
> vw_EmployeePurchases is a view and has fields like (EmployeeID,
> Sum(Purchases) as PurchTotal)
>
> I would like to create a new SP called SP_main that I can use to pass the
> desired date range into sp_EmployeeHours and then return a SELECT that
> contains (EmployeeID, Hours, FirstName, LastName, DepartmentId,
> DepartmentDesc) Basically the results of the SP and both the views. Thay all
> would have EmployeeID in common.
>
> What do you think? Thanks
>
> joe
>
>
>
- Next message: MGFoster: "Re: bit-wise and"
- Previous message: Ben: "RE: converting to sp_executesql"
- In reply to: Joe Williams: "Stored Procedure as part of SELECT?"
- Next in thread: Michael C: "Re: Stored Procedure as part of SELECT?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|