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 2005 Forums
 Transact-SQL (2005)
 Select statement

Author  Topic 

ararun
Starting Member

4 Posts

Posted - 2008-03-05 : 07:42:33
greetings

i want to use the select statement to select all the fields fromm the table except primary field.

thank you

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-05 : 07:45:56
What is the problem?

Select [columnname], columname2....etc
FROM Table




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-05 : 08:15:49
Make use of the output

select column_name+',' from information_schema.columns
where table_name='your table' and column_name<>'pkcol'

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-05 : 08:29:42
[code]SELECT c.ORDINAL_POSITION,
c.COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS AS c
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu ON kcu.TABLE_CATALOG = c.TABLE_CATALOG
AND kcu.TABLE_SCHEMA = c.TABLE_SCHEMA
AND kcu.TABLE_NAME = c.TABLE_NAME
AND kcu.COLUMN_NAME = c.COLUMN_NAME
WHERE kcu.ORDINAL_POSITION IS NULL
AND c.TABLE_SCHEMA = 'dbo'
AND c.TABLE_NAME = 'Activity'
ORDER BY c.ORDINAL_POSITION[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ararun
Starting Member

4 Posts

Posted - 2008-03-06 : 01:20:09
Thanks for ur replay.
Go to Top of Page
   

- Advertisement -