Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2004
    Posts
    5

    Post Unanswered: Accessing columns without the coulmn names

    Hi,
    I am looking for some help in MS SQL server. I want to access the columns of a table without using the names of the colulmns.

    Example - SELECT table1.field[1], table1.field[2] FROM table1;

    Any information to this effect is much appreciated.
    cheers/- Pradeep

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Can you explain how you want to use this information? There are probably ways to get you what you'd like, but there are at least as many really bad answers as really good ones.

    -PatP

  3. #3
    Join Date
    Aug 2004
    Posts
    5
    Pat, I need to get the value of columns 1 and 2 from the table EMP, while not being bothered as to the names of the columns.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd suggest something like:
    Code:
    SELECT c.COLUMN_NAME
       FROM INFORMATION_SCHEMA.COLUMNS AS c
       WHERE 'table1' = c.TABLE_NAME
          AND 1 = c.ORDINAL_POSITION
    See the BOL regarding INFORMATION_SCHEMA.COLUMNS for more details.

    -PatP

  5. #5
    Join Date
    Aug 2004
    Posts
    5
    Thanks a million Pat, this is what I was looking for.
    Are you a SQL Server DBA?

    cheers/- Pradeep

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Heck, I've been called even worse than than SQL DBA!

    I answer to just about anything from "Hey you" to "Data Modeler", and everything in between. I tend to refer to myself as a Resident Curmudgeon, which seems about as good a description as any to me!

    On a (very slightly) more serious note, yes, SQL DBA is one of the hats that I wear nearly every day.

    -PatP

  7. #7
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    SQL DataBase Analist
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  8. #8
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by derrickleggett
    SQL DataBase Analist
    I'm a what-ist ?!?!

    -PatP

  9. #9
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    i think i can translate ...

    ahem.


    NEH-HERD.


    Scott Davis
    "If you are not part of the solution, you are probably 1/5 of the suspension" RDJabarov.
    Last edited by Ruprect; 09-01-04 at 00:25.

  10. #10
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Now Scott, what the heck does that mean??? And when are you planning to have your Margarita? At my funeral?
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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