Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2001
    Location
    England
    Posts
    426

    Unanswered:

    I guess the question was 'how do you select a column by it's id'

    The name and id are held in syscolumns

    select name from syscolumns where colid = @i and id = object_id('tbl')

    so something like

    declare @sql varchar(1000)

    select @sql = 'select ' + name + ' from tbl'
    from syscolumns
    where colid = @i and id = object_id('tbl')

    exec(@sql)

  2. #2
    Join Date
    Jun 2003
    Posts
    5

    pulling data from tables using ColumnID

    This is exactly what I was looking for, except for one thing:-

    How can I put the reultant answer into a variable???

    My problem is I need to loop through columns in a table and refer to each column using its ColumnID, all this I can do, I can even pull back the Cloumn Name from the system tables, but I can't find a way of pulling the data from this into a variable...

    Please help

    thanks,

    Conan

Posting Permissions

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