Results 1 to 3 of 3

Thread: select query

  1. #1
    Join Date
    Feb 2004
    Posts
    5

    Post Unanswered: select query

    Thanks in advance for your help.
    I am new to transact-sql.
    Given a table name and column name as parameters. How can I fetch the values of the given column from the given table.

    something like: (which obviously does not work)
    select @given_column from @given_table where...

    Thanks
    Alex

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    declare @sql varchar(8000),@stable varchar(50),@scolumn varchar(50)

    set @stable='sysobjects'
    set @scolumn='name'
    set @sql='select '+@scolumn+' from '+ @stable

    exec(@sql)

    You could create stored procedure also.

  3. #3
    Join Date
    Feb 2004
    Posts
    5
    Originally posted by snail
    declare @sql varchar(8000),@stable varchar(50),@scolumn varchar(50)

    set @stable='sysobjects'
    set @scolumn='name'
    set @sql='select '+@scolumn+' from '+ @stable

    exec(@sql)

    You could create stored procedure also.

    Thanks a lot.

Posting Permissions

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