Nested stored procedure VS Exec procedures in same query - sql

I have a stored procedure for filling data mart and in this procedure, it calls many other procedures.
In those stored procedures I use temp table with same name. When I execute nested procedure something is wrong. These temp tables somehow stir and distort my data but if I execute these multiple procedures in query as script, that works fine.
I have no clue why it is happening and can you please give me some ideas? What is difference between executing multiple procedures in same query and using other procedure to exec this procedures.

Related

Execute SQL Server stored procedure from Oracle

I have an Oracle procedure that executes a SQL Server stored procedure. The SQL Server stored procedure executes one of three stored procedures based on an id field passed it from the Oracle procedure. Two of the stored procedure execute okay but the third does not.
The third stored procedure has several nested stored procedure calls. It performs some calculations and then inserts to 3 different tables and then some additional calculations and updates one of the tables it just inserted to. If I execute the stored procedure in SSMS it runs without issue. When it is executed from Oracle side I get nothing.
Could this because of the nesting but because of the implicit commits I see it work using SMSS? I tried doing a BEGIN Transaction in the starting stored procedure on the MS SQL Server side and a commit at the end where it should return. Still nothing. I have Try and Catch blocks in the MS SQL stored procedures and don't receive any errors.
Any suggestions would be greatly appreciated.
Thank you.
Does nothing means none of the inserts or updates show up in the tables. No error messages
As far as posting code; what specifically would you be interested in seeing? There are 4 stored procedures which have 100s of lines of code each.

How to execute one stored procedure that updates two tables Oracle

Procedure compiled with no errors to "Insert Into" two tables. How do I execute this? What is the right syntax to send the data for both tables into database? Using Oracle database.
Thanks.
To execute a stored procedure in oracle use execute.
e.g
execute procedure()
change procedure to whatever you have called your procedure

How to execute multiple stored procedures at a time?

I want to know that is there any way through which I can execute all my stored procedure at a time.
Presently I am executing each stored procedure using exec "Stored Procedure name" command.
And I have more than 200 stored procedure to be executed on my database.
Is there any easy way out to execute all these stored procedure at a single time as it is difficult for me to keep a track of them?
I suggest you write a stored procedure which calls the other ones.
Put all stored procedures inside a stored procedure,
CREATE PROCEDURE CallAllProcedure
AS
BEGIN
CALL Proc1
CALL Proc2
END
Assuming that you are using Query Analyzer, just put a GO in between all those stored proc and run script.
If you want to execute them all in parallel you could create a SQLJob and schedule them all to execute at the same time. Link below is general usage of SQL Jobs.
http://msdn.microsoft.com/en-us/library/ms190268.aspx
you can select all stored procedure names from sys.objects table querying type='P'. After you can use cursor for every stored procedure name to execute. But how about stored procedures with parameters? you must provide parameter values as well to avoid from errors.
You can use Service broker to do this async but I dont think it is a great idea to run 200 stored procs at the same time unless you are sure there will not be any contention on the DB

SQL Server: Load stored procedure results into table

I have a stored Procedure that returns multiple resultsets(to be specific three resultsets). I just need the first resultset. I am calling the original procedure from a different procedure where i will store the returned resultset into a #table and use it from my further processing.
Also, i can not modify the original stored procedure to achieve this.
Please help!
It's not possible to retrieve the second or further result set from a stored procedure inside SQL.
Two workarounds:
A scheduled job (like a C# program) that periodically calls the stored procedure and stores the result in tables that other procedures can use.
A SQL CLR stored procedure that does the same. The advantage of a SQL CLR procedure is that you can call it from normal SQL stored procedures, so you don't have to wait for the scheduled task.
I haven't tested this, but a work around would be to use OpenQuery and call your SP using it because "Although the query may return multiple result sets, OPENQUERY returns only the first one". OPENROWSET will also do the same...

SQL: Using Stored Procedure within a Stored Procedure

I have a few stored procedures that return the same set of data (same columns) to a user. The stored procedure called depends on certain conditions. These stored procedures are fairly intensive and are being run by every user of the system. I would like to create stored procedure that calls each of these procedures and stores the data on a separate table. I will then run this new stored procedure every 5 minutes or so and let the users pull from the new table.
T_OutboundCallList is a permanent table with the same columns as returned by the two stored procedures.
I would like something like the following but when I try to run this it just runs continuously and I have to stop the procedure.
BEGIN
TRUNCATE TABLE T_OutboundCallList
INSERT T_OutboundCallList EXECUTE p_LeadVendor_GetCallsForCallList
INSERT T_OutboundCallList EXECUTE p_CallLog_GetAbandonedCallsCallList
END
Each of the procedures (*CallList) return a list of calls to be made and I do want them entered into the new table in this order (LeadVendor calls before AbandonedCalls). I also need to clear the table before adding the calls as there may be new calls that need to be higher in the list.
Is there some problem with this procedure that I am not seeing?
Thanks,
Brian
Without seeing the code in your *CallList procs it is hard to say what issue you are having. You should have the insert commands inside of your nested procedure. You can use the results of a procedure to insert data, but not like you are above. It is using OPENROWSET, and I think you will be better off the way I suggested.