user1795131
user1795131

Reputation: 47

Obtain column names from query using wildcard

When using select * from dbo.myTable, is there a way with a join or shortcut to get the column names represented from the wildcard?

Looking for a shorthand use so I don't have to type out 80 column names.

Thanks!

Upvotes: 1

Views: 74

Answers (2)

ttallierchio
ttallierchio

Reputation: 460

here is a script that will work on sql server(assuming that is your vendor as you have dbo in your example)

declare @table as varchar(max) = 'spt_monitor' -- replace this with your table

select 'select ' +  stuff((SELECT ', ' + column_name
FROM information_schema.columns
WHERE table_name = @table for xml path('')),1,1,'')  + ' from ' + @table 

copy and paste the output and enjoy.

Upvotes: 1

Arx
Arx

Reputation: 123

I use SQLComplete for this..

https://www.devart.com/dbforge/sql/sqlcomplete/

Not quite what you want, but it is an option.

Upvotes: 1

Related Questions