jpnasab 81740 (9/30/2013)
Create function [dbo].[AF_TableColumns](@table_name nvarchar(55))
returns nvarchar(4000) as
declare @str nvarchar(4000)
select @str = cast(rtrim(ltrim(column_name)) as nvarchar(500)) + coalesce(' ' + @str , ' ')
where table_name = @table_name
group by table_name, column_name, ordinal_position
order by ordinal_position DESC
--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 Moden's splitter
.Cross Tabs and Pivots, Part 1 – Converting Rows to Columns Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs Understanding and Using APPLY (Part 1)Understanding and Using APPLY (Part 2)