Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Excluding fields
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01202810
Message ID:
01202819
Vues:
11
>>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!
____________________________________
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform