to the column list of a table in a form ready to replace the '*' in
Select * from mytableby the complete column list?
Well I definitely did it too often. It is so easy to write a stored procedure for the same purpose:
if object_id('build_columnlist') > 0now just type
drop procedure build_columnlist
go
create procedure dbo.build_columnlist @table_name sysname
as
begin
declare @cols varchar(max) -- varchar(8000) for sql server 2000
select @cols = case when @cols is null then c.name else @cols + ', ' + c.name end
from syscolumns c join sysobjects o on c.id = o.id
where o.name = @table_name order by colorder
select @cols
end
go
exec build_columnlist 'mytable'and when you display the result as text, it is there ready to copy and past.
Oops did you change extra | options | max characters pro column to 8000 ?
That was for Query Analyzer, SQL-Managemantstudio has a similar setting.
And note the trick of updating a variable using a select statement.
defaults are always wrong.
Bernd
Keine Kommentare:
Kommentar veröffentlichen