March 25, 2013 at 11:57 pm
If My table consist of 250 colum and i want to select 200 column so it is possible to write query to select 200 column without write all column name in select statement
March 26, 2013 at 12:23 am
No. You will have to write the 200 columns in your SELECT statement.
You can save some typing effort by using system tables like INFORMATION_SCHEMA.COLUMNS to generate comma-seperated column names and them removing the unwanted columns.
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 26, 2013 at 12:27 am
Thanks!! can you give one example
March 26, 2013 at 12:36 am
You can run the below mentioned query to get the list of comma-separated columns.
You can then copy the results and use them in your SELECT statement
SELECTCOLUMN_NAME + ','
FROMINFORMATION_SCHEMA.COLUMNS
WHERETABLE_NAME = 'YourTableName' -- Replace YourTableName with the your actual table name
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 26, 2013 at 7:53 am
Kingston Dhasian (3/26/2013)
You can run the below mentioned query to get the list of comma-separated columns.You can then copy the results and use them in your SELECT statement
SELECTCOLUMN_NAME + ','
FROMINFORMATION_SCHEMA.COLUMNS
WHERETABLE_NAME = 'YourTableName' -- Replace YourTableName with the your actual table name
If you want to save yourself the hassle of returning this in all those rows which forces you to do a lot of editing you can add FOR XML to this.
SELECTCOLUMN_NAME + ', '
FROMINFORMATION_SCHEMA.COLUMNS
WHERETABLE_NAME = 'YourTableName' -- Replace YourTableName with the your actual table name
FOR XML PATH('')
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy