How to Obtain the SQL Select statement from a View

  • Hi Guys

    I have a View defined in my database.

    In a Stored Procedure I need to retrieve the SQL Select statement from the View and store it in a variable.

    Is this possible?

    Sound easy, but cant find anything out there.

    Any help is appreciated.

    Please, lets not get into a long discussion as to why I need to do this, I just do.

    Cheers

    Doug

  • Found it. I used the following.

    Set @Sql = (SELECT m.definition FROM sys.sql_modules m, sys.views v WHERE m.object_id = v.object_id AND v.name = 'view_name')

    Tks

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

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