Traversing Column rows
-
Hi, I am Writing an sql that returns a single record which is row from a table. In the same sql i would like to traverse through the columns of this row. How can I do that? Is it possible to access the columns in SQL through indexing for example like column[1]? Thanks for your time and help
-
Hi, I am Writing an sql that returns a single record which is row from a table. In the same sql i would like to traverse through the columns of this row. How can I do that? Is it possible to access the columns in SQL through indexing for example like column[1]? Thanks for your time and help
You cannot refer to a column by it's ordinal (1) in SQL unless you use dynamic SQL in which case you look up the column name from the schema view and build a string to execute.
Never underestimate the power of human stupidity RAH
-
You cannot refer to a column by it's ordinal (1) in SQL unless you use dynamic SQL in which case you look up the column name from the schema view and build a string to execute.
Never underestimate the power of human stupidity RAH
thanks for your reply. I am using Dynamic Sql but the problem is that I don't know the name of the column to fetch for, thats why I was trying to find a way similar to indexing.Is there a way?
-
thanks for your reply. I am using Dynamic Sql but the problem is that I don't know the name of the column to fetch for, thats why I was trying to find a way similar to indexing.Is there a way?
Take a look into the information schema views (under system views in Management Studio)
INFORMATION_SCHEMA.COLUMNS
is the one you wantNever underestimate the power of human stupidity RAH