January 18, 2013 at 3:31 am
Hi all,
how to get the column names from excel as comma separated string in sql server
number of columns will be dynamic....
like
File contains:column1 column2 column3
string as: column1,column2,column3
January 18, 2013 at 9:51 pm
Can you be a bit more specific about what you are trying to do? Is the first row in your spreadsheet the column names? If you can explain in more detail I am sure we can come up with a solution. I can think of 3-4 ways off the top of my head this could be done.
_______________________________________________________________
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/
January 20, 2013 at 10:04 pm
hi Sean Lange,
I want first row(column name) of excel as one comma separated string in sql .number of columns in excel will be dynamic.for example today it will come with 10 column,tomorrow it will be 15 column.
January 21, 2013 at 7:24 am
Load it into a table which I would assume you are doing anyway. Then you just query sys.columns to get your list.
SELECT Stuff((SELECT ', ' + name
FROM sys.columns where object_id = object_id('YourTableNameHere')
order by column_id
FOR XML PATH('')), 1, 1, '')
--EDIT--
Spelling bug
_______________________________________________________________
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/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply