Can i use column number instead of column name in where condition of a select query in SQL Server 2005?

sql, sql-server, sql-server-2005

Solution

no you cannot directly, just drag the column name you want from the object explorer into your query...you don't need to type it

Hit F8, this will open Object Browser. Navigate to DatabaseName/TableName/Columns. Click on the column folder and drag the column folder into the Code Window. Upon release you will see that all the column names are in the Code Window.

Another option would be (and I do not recommend this )

you would need to use dynamic SQL and do a lookup in information_schema.columns and look for ordinal_position to get the column number. If you need column 5 you would get ordinal_position 5 to grab the column name. this however is messy

Problem

can we use column number instead of column name in where condition of a select query in SQL Server 2005 so that even if the column name is so long. thanks in advance.

Original source