December 27, 2019 at 2:33 pm
I will force the cursorย to execute the procedure first then execute execute the others
my script is as follows
create procedure [dbo].[usp_IntegrationAllStoredProcedures]
as
set nocount on;
DECLARE abc CURSOR FOR
SELECT ROUTINE_NAME
FROM INFORMATION_SCHEMA.routines
WHERE ROUTINE_TYPE = 'PROCEDURE' and right(ROUTINE_NAME,4)='Bulk' and ROUTINE_NAME !='usp_Integration_CONTRAT_EMISSION_Bulk'
OPEN abc
DECLARE @RoutineName varchar(128)
-- Build select string once
DECLARE @SQLString nvarchar(2048)
FETCH NEXT FROM abc
INTO @RoutineName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQLString = 'exec'+ ' ' + @RoutineName
print (@SQLString)
--EXECUTE sp_ExecuteSQL @SQLString
FETCH NEXT FROM abc
INTO @RoutineName
END
CLOSE abc
DEALLOCATE abc
Print 'Manque Procedure usp_Integration_CONTRAT_EMISSION_Bulk'
set nocount off;
GO
my goal is to execute my procedure usp_Integration_CONTRAT_Bulk the first
who has an idea please
December 27, 2019 at 2:49 pm
DECLARE abc CURSOR FOR
SELECT ROUTINE_NAME
FROM INFORMATION_SCHEMA.routines
WHERE ROUTINE_TYPE = 'PROCEDURE'
and right(ROUTINE_NAME,4)='Bulk'
and ROUTINE_NAME !='usp_Integration_CONTRAT_EMISSION_Bulk'
order by case ROUTINE_NAME
when 'usp_Integration_CONTRAT_Bulk' THEN ' ' + ROUTINE_NAME
else ROUTINE_NAME
end
December 27, 2019 at 4:02 pm
If order of execution is important for 1 procedure, it's likely inevitable that order of execution will be come a necessity for others, as well.ย My recommendation is to build a numbered control table and use that as the source of your control cursor.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 29, 2019 at 2:16 pm
You said cursor, wash your mouth out and say three Hail Marys to repent :-/
Far away is close at hand in the images of elsewhere.
Anon.
December 29, 2019 at 5:16 pm
You said cursor, wash your mouth out and say three Hail Marys to repent :-/
๐ ๐ ๐
Agreed. Unless the list of stored procedures was in flux and needed to accommodate both deletions and additions of stored procedures , I don't understand why someone wouldn't just create a top level procedure to call the various procedures.ย Even then, a cursor isn't necessary.ย One could simply concatenate the EXEC commands.ย But, a cursor doesn't actually cause a performance issue here because it's strictly a control cursor.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 29, 2019 at 6:24 pm
My post was in jest ๐
But agree with your post, I have a proc that calls several procs in a specific order with some logic to decide whether to call some of them.
Far away is close at hand in the images of elsewhere.
Anon.
December 29, 2019 at 8:39 pm
Oh no... not to worry.ย I got "the jest" of it. ๐ย That's why the smiley faces.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply