jpnasab 81740 (9/30/2013)
Create function [dbo].[AF_TableColumns](@table_name nvarchar(55))returns nvarchar(4000) as
begin
declare @STR nvarchar(4000)
select @STR = cast(rtrim(ltrim(column_name)) as nvarchar(500)) + coalesce('' + @STR , '')
from information_schema.columns
where table_name = @table_name
group by table_name, column_name, ordinal_position
order by ordinal_position DESC
return @STR
end
--select dbo.AF_TableColumns('YourTable') Select * from YourTable
Gosh that is a pretty limited function that doesn't help for this post at all. The OP is looking for the column names from a view.
And btw, you should not use the information_schema dmv's to view the schema. You should sys.objects.
http://technet.microsoft.com/en-us/library/ms188348.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/