Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
cognos79
Posting Yak Master
241 Posts |
Posted - 2007-05-15 : 09:47:27
|
I want to import an excel spreadsheet into database.excel has following file format:------------------------------------Id col1 col2 col3 col41 20 21 22 232 30 31 32 33The above records have to be split into multiple records like shown below. The database table has following structure:--------------------------------------Id col1 201 211 221 232 302 312 322 33How can i do this. |
|
sshelper
Posting Yak Master
216 Posts |
Posted - 2007-05-15 : 10:13:43
|
First load you file into a temporary table in SQL Server. Then you can use the following query to load it to your final table:SELECT [ID], [Col1] AS [Col] FROM YourTempTableUNION ALLSELECT [ID], [Col2] AS [Col] FROM YourTempTableUNION ALLSELECT [ID], [Col3] AS [Col] FROM YourTempTableUNION ALLSELECT [ID], [Col4] AS [Col] FROM YourTempTableSQL Server Helperhttp://www.sql-server-helper.com |
|
|
|
|
|