How to Share Data Between Stored Procedures in MS SQL
2009-Гру-18, П'ятниця 13:04Method | In/Out | Rewrite callee? | Required version | Comment |
---|---|---|---|---|
Output | Yes | Not generally applicable, but sometimes overlooked. | ||
Table-valued Functions | Output | Yes | Often the best choice for output-only, but there are several restrictions. | |
Inline Functions |
Use this to reuse a single SELECT. | |||
Multi-statement Functions |
When you need to encapsulate more complex logic. | |||
Using a Table | In/Out | Yes | The most general solution. My favoured choice for input/output scenarios. | |
Sharing a Temp Table | Mainly for a single pair of caller/callee. | |||
Process-keyed Table |
Best choice for many callers to the same callee. | |||
Global Temp Tables |
A variation of process-keyed. | |||
Table-valued Parameters | Input | Yes | SQL 2008 | Mainly useful when passing data from a client. |
Output | No | Deceivingly appealing, but should be used sparingly. | ||
Output | No | SQL 2005 | Complex, but useful as a last resort when INSERT-EXEC does not work. | |
Output | No | Tricky with many pitfalls. Discouraged. | ||
In/Out | Yes | SQL 2005 | A bit of a kludge, but not without advantages. | |
Using Cursor Variables | Output | Yes | Not recommendable. |
Read there ...