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
 exclude columns

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2006-05-13 : 09:52:46
Hi

i wanna exclude some columns from my select statement. i do NOT wanna columns starting with 1,2,3,4,5 and I. How can i do it?

thanks

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-05-13 : 10:05:16
not sure what you mean...

select columns...
from tablename
where columnname not like '[1-5]%'

--------------------
keeping it simple...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-13 : 10:16:38
don't use select *
specify the column that you want specifically in the select statement


KH

Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-13 : 12:55:39
DECLARE @s VARCHAR(8000)
SELECT @s=''

SELECT @s=@s + Column_name + ','
from INFORMATION_SCHEMA.Columns
where table_name = 'MyTbl' and Column_name not like '[1-5]%'

set @s = left(@s, Datalength(@s)-1)
set @s = 'Select ' + @s + ' from MyTbl'
execute ( @s)


Srinika
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2006-05-13 : 16:40:16
thanks so much
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2006-05-14 : 13:16:10
Just out of curiosity....why would you not just drag/drop the columns from the object explorer, delete the ones you don't need, and call it a day. That way, you don't have to use extra resources and dynamic SQL every time you run this query.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -