Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-01-31 : 08:15:12
|
| Dhruba writes "How to call a (child) stored procedure which returns some data(selects something from a table) , from a (parent) stored procedure which inserts those data (returned by the child one)?" |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2005-01-31 : 08:31:26
|
Weeeeeeeeeeeeeeellllllllllll, if I read your English right (and there's a good possibility I didn't), then:USE NorthwindGOCREATE TABLE test_insert(data VARCHAR(55))GOINSERT test_insert(data) SELECT 'URRRR?'SELECT data FROM test_insertGOCREATE PROCEDURE select_stuffASSELECT data FROM test_insert WHERE data = 'URRRRRRR?'GOCREATE PROCEDURE master_stuffASINSERT test_insert(data) SELECT 'URRRRRRR?'EXEC select_stuffGOEXEC master_stuffGODROP TABLE test_insertDROP PROCEDURE select_stuffDROP PROCEDURE master_stuffGO Nothing magical!!!!MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
SqlStar
Posting Yak Master
121 Posts |
Posted - 2005-02-01 : 04:50:34
|
| Hi,You can achieve your task using User Defined Functions instead of stored procedure. Just create a function, it should contain that "child" stored procedure's select statement. See the following example for your idea.USE pubsGOCREATE FUNCTION SalesByStore (@storeid varchar(30))RETURNS TABLEASRETURN (SELECT title, qty FROM sales s, titles t WHERE s.stor_id = @storeid and t.title_id = s.title_id)GOCreate Table Test(title varchar(100), qty int)GOInsert Into TestSelect * From dbo.SalesByStore(6380)GOSelect * from TestGO:) While we stop to think, we often miss our opportunity :) |
 |
|
|
|
|
|