Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to select nth column in a SELECT clause from a table/view

I've this GIGANTIC view with several hundred columns and I need to select 114th column something like:

SELECT "144" FROM MyView;

PS: Obviously, I don't know the name of the column. I just copied the results row into an Excel file, searched for a particular value that is in EJ column so I want to select all rows showing only nth column in my view to do my further debugging.

Cheers!

like image 591
Vishal Seth Avatar asked May 04 '10 20:05

Vishal Seth


People also ask

How do you select nth record in a table?

ROW_NUMBER (Window Function) ROW_NUMBER (Window Function) is a standard way of selecting the nth row of a table. It is supported by all the major databases like MySQL, SQL Server, Oracle, PostgreSQL, SQLite, etc.

How do I select certain columns in a table?

Click the top edge of the column header or the column in the table. The following selection arrow appears to indicate that clicking selects the column.

How do I select a specific column from a table in SQL?

To select columns, choose one of the following options: Type SELECT , followed by the names of the columns in the order that you want them to appear on the report. Use commas to separate the column names.


2 Answers

If you are using MS SQL Server you can

sp_help ViewName

and then scroll to the 144th column in the Column_name result set to see what the name of that column is.

Additionally you can choose "Copy with Headers" in the result pane in SQL Server Management Studio and paste the result set into Excel with the headers (column names) intact.

like image 136
cfeduke Avatar answered Nov 02 '22 04:11

cfeduke


I'd suggest giving all the columns names based upon their Excel column name. There should be an excel solution to make the first row equal to the column name (ie AA, BB, etc). Then do your import, then select based upon the column name which should be computable.

like image 42
MindStalker Avatar answered Nov 02 '22 05:11

MindStalker