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:
01202821
Views:
10
>>>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
Thanks.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform