Run Storedprocedure syntax dynamically in database

  • I have storedprocedure .sql file, it contains content from "create proc ......". I want to run this dynamically.

    I select .sql file from one location and read this and send content as an parameter in a storedprocedure. Now i want to run this content. What can i do? pls help me.:-)

  • please provide your DDL scripts so that we can assit you better.

  • Hi,

    I made one sp like as:

    Create proc sarvesh

    as

    Begin

    Select 0

    end

    I want to run this script at client side from my side. I send this as an parameter in string in other sp.

    Can you tell me, how can i run this?

  • do you want to run the full string including the CREATE PROC, or just the contents of the proc

    EG EXEC ProcName or CREATE PROC ProcName.....

    Also you have only provided one part of the DDL, we need the other part which is the execution proc

  • Hi,

    I wrote following syntax:

    exec 'Create proc sarvesh as Begin Select 0 end'

    but it gives error, pls run this and send me right syntax.

  • declare @string varchar(max)

    set @string = 'SOME STRING'

    sp_executesql (@string)

    or

    EXEC (@string)

  • Sarvesh Kumar Gupta (12/6/2011)


    Hi,

    I wrote following syntax:

    exec 'Create proc sarvesh as Begin Select 0 end'

    but it gives error, pls run this and send me right syntax.

    As anthony said, you can do it using SP_ExecuteSQL like this:

    SET QUOTED_IDENTIFIER OFF

    GO

    DECLARE @SQLText NVARCHAR(MAX)

    SET @SQLText = "SELECT 'It is working.'"

    Execute SP_ExecuteSQL @statement = @SQLText


    Sujeet Singh

Viewing 7 posts - 1 through 6 (of 6 total)

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