Dynamic script for creating (view, Stored procedure,function) in selected db.

  • hi all,

    i need a Dynamic script for creating (view, Stored procedure,function) in selected db.

    for example

    like if i have a 10 db whose name start with XX_

    where i can apply a

    create view statement on that db's where the db name start with XX_

    Any Suggestion or Help is Appreciated !!!

  • use this to fetch DB Names

    Select name from sys.databases

    where name like 'xx%'

    and run your view or procedures using "use DBNAME and query".

    can we know what are you trying to do it?

    Regards
    Durai Nagarajan

  • durai nagarajan (3/1/2012)


    use this to fetch DB Names

    Select name from sys.databases

    where name like 'xx%'

    and run your view or procedures using "use DBNAME and query".

    can we know what are you trying to do it?

    how abt this

    DECLARE @grantExecute varchar(8000)

    select @grantExecute = 'IF ''?'' NOT IN(''master'', ''model'', ''msdb'', ''tempdb'') and ''?'' like ''CC_%'' BEGIN USE [?]

    here the sql query which i want to execute with a (')

  • You mean execute this query by means of sp_msforeachdb ?

  • ffoerster (3/5/2012)


    You mean execute this query by means of sp_msforeachdb ?

    yes by sp_msforeachdb

    do u have any better script or any script please put on the forum.

Viewing 5 posts - 1 through 4 (of 4 total)

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