0

I have a table with over a hundred columns, but I only want to select the the columns named nvarchar1, nvarchar2, ... nvarchar64. All of these 64 columns are next to each other so I was thinking maybe there is a way to select using column indices, but I couldn't find a solution.

Note: I don't want to do the obvious solution,

SELECT nvarchar1,
       nvarchar2,
       ...
       nvarchar64
...
3
  • What DBMS are you using? And have you ever come across the problem of "repeating groups" with respect to First normal form? If you can, a table redesign might help you more than anything else. Commented Jul 20, 2012 at 13:34
  • I think it's 2005 and I don't know what your second question means. Commented Jul 20, 2012 at 13:39
  • 1
    I'm going to take it you mean SQL Server 2005 (as opposed to Oracle, MySql, SQLite, etc.), so I'll retag the question as such. For my second question, if you haven't read much on database normalization, the article I linked to in my comment explains some problems you may encounter with repeating columns/groups. Commented Jul 20, 2012 at 13:42

1 Answer 1

3

Make use of the result from this query:

select  column_name + ','
from    information_schema.columns
where   table_name = 'your table name'
        and column_name like 'nvarchar%'
Sign up to request clarification or add additional context in comments.

2 Comments

The result shows the names of the columns, but how do I use it in a select? Sorry, I'm still very new to sql.
Copy the result and use it in your select statement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.