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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select ??? From Table1

Author  Topic 

Nemisis
Starting Member

8 Posts

Posted - 2006-03-09 : 05:06:18
Hi guys,

Everyone know that the following will select all fields within a table:

Select * From table1

If i change the * for individual field names, then i can select specific fields.

Select id, name, description, hair, eyes from table1

But is it possible to somehow, select all fields within a table, but with a parameter list of fields you dont want selected?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-03-09 : 06:59:06
no

Go with the flow & have fun! Else fight the flow
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-09 : 08:00:15
Why do you want to do this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-03-09 : 08:11:41
Is this what u want?

DECLARE @s VARCHAR(8000)
SELECT @s=@s + Column_name + ','
from INFORMATION_SCHEMA.Columns
where table_name = 'MyTable' and Column_name not in ( 'Unwanted_Column1' , 'Unwanted_Column2' ....)
set @s = left(@s, Datalength(@s)-1)
set @s = 'Select ' + @s + ' from MyTable'
execute ( @s)


If u want the unwanted columns to be passed as parameters, u can modify the above with Unwanted columns as parameters and have the code in a stored procedure and modify accordingly to get the output.
Go to Top of Page

Nemisis
Starting Member

8 Posts

Posted - 2006-03-15 : 09:13:07
i know you can query the system tables, but didnt know if there was a proper function for it.

Thanks anyway everyone
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-15 : 09:16:13
Still you didnt tell us why you need this

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -