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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select * and De-select

Author  Topic 

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-09 : 02:16:09
hi all,

is there any command to exclude columns when we select all..
could be useful when the columns are too many, yet we need to select many2 column, but not all..

select * , deselect column21, column22, ...

is this possible?to select ALL with some deselect columns...

thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-09 : 02:21:44
there isn't a way. You have to specify the column name that you required.


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-09 : 02:32:11
Or you can make use of the script here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53384


KH

Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-09 : 02:56:03
thanks btw khtan.
i've follow the link, it suggest first N column, how about select x from column 1-100?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-09 : 03:01:02
the script is there, you can modify it to your own requirements


KH

Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-09 : 03:12:40
i always wonder, is SP = scripts?
how do we write functions in sql server?
pliz bear with me- :p

~~~Focus on problem, not solution~~~
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-09 : 03:50:24
Sorry i mean Stored Procedure


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-09 : 04:06:46
quote:
Originally posted by maya_zakry

thanks btw khtan.
i've follow the link, it suggest first N column, how about select x from column 1-100?



Create 2 new parameter : @start int, @end int
changed the stored procedure to check for ORDINAL_POSITION between @start and @end.

WHERE ORDINAL_POSITION BETWEEN @start AND @end



KH

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-01-09 : 04:20:46
"to select ALL with some deselect columns..."

By the by, you should list the columns you want, and not use SELECT *, because it is more likely that your query plan will be cached, which helps performance.

Also, someone may add extra columns to your table in the future, and if you do SELECT * you will be pulling that extra database back to your application - which wastes time and bandwidth - particularly if the newly added columns are datatype IMAGE containing massive images files!!!

Kristen
Go to Top of Page
   

- Advertisement -