Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excluding fields
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01202810
Message ID:
01202819
Views:
12
>>Thanks
>
>Use this handy function
>Re: INSERT not as maintainable? Thread #1140411 Message #1140531

Cool!

And in case you need to do it for a SQL Server table..
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE function [dbo].[Util_ColumnString] (@TableName varchar(MAX))
returns varchar(MAX)

as

BEGIN

/*	
	Tired of spelling out dozens of columns in a select query^ 
	This function returns a string suitable for use as a column list for a specified table.
	The parameter is the table name to get a column list for.

*/


	declare @ColumnName varchar(MAX)
	declare @ColumnString varchar(MAX)

	set @ColumnString = ''

	declare #TableInfo Cursor Local forward_Only Static for 
		SELECT COLUMN_NAME
		FROM INFORMATION_SCHEMA.COLUMNS
		WHERE TABLE_NAME = @TableName

	open #TableInfo

	fetch next from #TableInfo into @ColumnName

	while @@Fetch_Status = 0
	begin

		set @ColumnString = @ColumnString + '['+ltrim(rtrim(@Columnname))+']'+','
		
		fetch next from #TableInfo into @ColumnName

	end

	close #TableInfo
	deallocate #TableInfo


	if len(@columnString)>0
		set @ColumnString = substring(@ColumnString,1,len(@ColumnString)-1)


	RETURN @ColumnString

END
____________________________________

Don't Tread on Me

Overthrow the federal government NOW!
____________________________________
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform