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 |
|
sdiwi
Starting Member
27 Posts |
Posted - 2005-08-25 : 12:44:38
|
hi.maybe, you can guess by the title of the topic what my problem is about.i am writing a stored procedure.inside this sp, i want to retreive and use the values of another sp.my code somehow looks like this:CREATE PROCEDURE test @somevar INTAS.....IF (@@ERROR <> 0) BEGIN SET @sql = 'EXEC sp_fkeys ' + @table; --this is the point where i have no clue anymore... --i'd just like to write the results in a TABLE var or something. --i have no choice, i have to use this sp (no udf :(...) EXEC sp_executesql @sql; --at this point i want to continue working with the results... ENDELSE BEGIN PRINT 'SUCCESS...'; END;GO anyone got an idea or knows how to do it?you would really do me a great favor and save my day ;)thanks for your help.cya around,peace,sdiwi. |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-25 : 13:24:46
|
you just need to create a #temp table with the same structure as the output of sp_fkeys. Then insert the results of your sp_executesql command:create table #fkeys (PKTABLE_QUALIFIER sysname ,PKTABLE_OWNER sysname ,PKTABLE_NAME sysname ,PKCOLUMN_NAME sysname ,FKTABLE_QUALIFIER sysname ,FKTABLE_OWNER sysname ,FKTABLE_NAME sysname ,FKCOLUMN_NAME varchar(32) ,KEY_SEQ smallint ,UPDATE_RULE smallint ,DELETE_RULE smallint ,FK_NAME sysname ,PK_NAME sysname ,DEFERRABILITY smallint)insert #fkeysexec sp_executesql @sql Be One with the OptimizerTG |
 |
|
|
sdiwi
Starting Member
27 Posts |
Posted - 2005-08-25 : 13:52:40
|
thanks for your reply, tg. i'll try it out tomorrow back @work. would something like DECLARE @table TABLE( PKTABLE_QUALIFIER sysname ,PKTABLE_OWNER sysname ,PKTABLE_NAME sysname ,PKCOLUMN_NAME sysname ,FKTABLE_QUALIFIER sysname ,FKTABLE_OWNER sysname ,FKTABLE_NAME sysname ,FKCOLUMN_NAME varchar(32) ,KEY_SEQ smallint ,UPDATE_RULE smallint ,DELETE_RULE smallint ,FK_NAME sysname ,PK_NAME sysname ,DEFERRABILITY smallint);INSERT INTO @table (EXEC sp_executesql(@sql)); work then, too (i cannot try it out right now, that's why i'm asking)?would be a little more elegant in my eyes - if it's working... thanks again,peace. |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-25 : 14:17:04
|
| nope sorry, you can't exec into a table variable. I know, bummer.exec and table variables are like in-laws, no matter how much you want them to get along, they just won't be in the same room together.Be One with the OptimizerTG |
 |
|
|
sdiwi
Starting Member
27 Posts |
Posted - 2005-08-26 : 04:00:31
|
| ok, thanks again. seems like temp tables are the only solution;(...i just tried to get the results of sp_fkeys returned by a table function, to make the handling easier. however, i cannot access temp tables inside of a function.is there a workaround or do i have to use sps?thank you,byby,sdiwi. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-26 : 04:16:57
|
| Use stored Procedure instead of FunctionMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|