Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010

    Unanswered: Cannot use procedures paramaters dynamically

    I want to gets the values of all the parameters inside the procs.
    but want to do this dynamically.
    What I am doing over here is that I fetches all the parameters for a particular proc using syscolumns table

    for e.g.
    declare @sqlstring varchar(255)
    select @sqlstring = name
    from syscolumns c
    where = object_id('TTG_FuturesDeals') and

    EXEC("SELECT " +@sqlstring)

    This is an example for just one parameter.
    Unfortunately its throwing me an error: Parameter must be declare.
    Any help will be appreciated.

  2. #2
    Join Date
    Aug 2010
    the problem with your code is, that the result
    of @sqlstring would be "select uid"
    which is not a valid sql statement, you would need
    eg select 'uid'

    Maybe you try the follwing:

    declare @sqlstring varchar(255)
    ,@sqlstmt varchar (500)

    select top 1 @sqlstring = name
    from syscolumns c

    SET @sqlstmt = 'select '''+@sqlstring +'''' -- as it is a varchar you have to double qute it
    print @sqlstmt


    -- even this will work:
    EXEC('select '''+@sqlstring +'''')

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts