Execute Multiple Exec Command in a string

  • Hi all,

    I have a store procedure that generates this dynamic output

    Execute generate_email '1'; Execute generate_email '9';

    which i would like to execute them in at once. how do you do this?

    I am trying to avoid cursor here so I tried going into concatenating all those execute statements into a string and execute them at the same time. is this possible?

  • Hi

    I'm not sure if I got you, but try this:

    CREATE PROCEDURE usp_TestPrint

    @text NVARCHAR(128)

    AS

    PRINT @text

    GO

    DECLARE @sql NVARCHAR(MAX)

    SELECT TOP(10)

    @sql = ISNULL(@sql, '') + CHAR(10) + N'EXECUTE usp_TestPrint ''' + name + ''''

    FROM sys.objects

    EXECUTE (@sql)

    Greets

    Flo

  • Hi,

    try this

    DECLARE @abc VARCHAR(1000)

    SELECT @abc = 'SELECT * FROM syssegments; SELECT * FROM sysconstraints;'

    select @abc = replace(@abc,';',' GO')

    exec (@abc)

    ARUN SAS

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply