Need Help in SP

  • hi,

    is any one help me in making the correct stored proc??

    I want to pass column and table name in the query using the stored proc:

    For example:

    --------------

    create proc USP_Generic @columns varchar(50), @tbl varchar(100)

    As

    select @columns from @tbl

    Go

    -------------

    Please give me the correct script

    Thanx

  • Why would you want to do this?

    Look for Dynamic sql. But you shouldn't use it if you don't understand it.

  • You could do it. But I wouldnt recommend it.

    You would need to use Dynamic SQL and use sp_ExecuteSQL to execute the string.

    Something along these lines:

    DECLARE @sql nvarchar(500)

    SET @sql = 'SELECT ' + @columns +' FROM' + @tbl

    sp_ExecuteSQL N'@sql

    Check out books on line for sp_ExecuteSql and they have more info with sample code.

    ******************
    Dinakar Nethi
    Life is short. Enjoy it.
    ******************

  • Thanx buddy, Its working..

    I really love this ..

    Thanx for prompt response..

    Noman

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

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