Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
aex
Yak Posting Veteran
60 Posts |
Posted - 2006-05-29 : 06:23:54
|
| Hi, I hv one problem here. I hv a table which has 50 columns. If I want to select all columns, I can write:select * from table1But my problem is, I want to select only the first 49 columns, then my query would be:select col_1, col_2, col_3... from table1As see, it would be a tedious task if the table hv more than 50 columns when the above criteria is to be met.So, is there any way for me to select only those columns that I want by filtering the last one?Thanks in advance for any reply.aex |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-05-29 : 06:35:24
|
I dont think there is a direct way that you can select the first n number of columns you require.. you need to via dynamic sql somthing like this Declare @strQry varchar(8000)Set @strQry = 'Select 'Select Top 49 @strQry = @strQry + Column_Name + ',' From Information_Schema.Columns Where Table_Name = '<Your Table>'Select @strQry = left(@strQry,len(@strQry)-1) + ' From <Your Table> 'Exec(@strQry) I guess rather then doing this its simple to write a column name in the select query you can use query analyser object brower to write a simple select statement which will consist of all the columns and then remove the columns which you dont wantIf Debugging is the process of removing Bugs then i Guess programming should be process of Adding them. |
 |
|
|
aex
Yak Posting Veteran
60 Posts |
Posted - 2006-05-29 : 06:39:59
|
Thanks a lot khtan for providing me a very good link and from there I am able to solve the problem.Thanks also to chiragkhabaria for the reply. I really appreciate the solution and suggestion that you give.Thanks again guys, thanks. aex |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|