How to get mutlple columns from database except one column

Posted by Mahesh_Chs under ASP.NET on 10/18/2012 | Points: 10 | Views : 1007 | Status : [Member] | Replies : 4
hii

i have a table in sqlserver with 30 fields, i want to select all the fileds except one field. Is there any shortcut for this.


Thank You
Mahesh chayanam




Responses

Posted by: Lalitha86 on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
Select * From TAble_name ;


Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahesh_Chs on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
hi

This query wil give all the columns in the table. but i dont want this...


suppose if i have a table with fields of id,name,sal, i don't want sal , i want only id and name

yes we can write select id,name from table name but in my table there are nearly 35-40 columns.

so i am asking is there any short cut to get all columns except one column


Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalitha86 on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
do sp_help table_name you will get all column names below

In this U will get all column name copy that and expect the salary in all other just put comma
and do as


select col1,col2,......... from table_name ;


Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Me_Himanshu on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
I think ther is no direct way of doing what you have asked,rest experts may tell.
But it could be done using the temp table like

select * into #temp from yourtablename //this will copy all the data from your table to the temp table

alter table #temp drop column sal // this will drop the column you dont want to show from temp table

and lastly

select * from #temp

Regrds




Himanshu Pandey

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response