?
Solved

Excel reading, comma seperation

Posted on 2007-03-26
1
Medium Priority
?
311 Views
Last Modified: 2010-05-18
I'm reading data from an excel spreadsheet to insert into a database table and have a question.

In one column in Excel, I have "LastName,FirstName". How can I split this out, so when I come to do the insert I can insert LastName and FirstName seperately?
0
Comment
Question by:PeterErhard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 18796317
It depends, if you are using DTS than it is as simple as using the VBScript Split() function and mapping them into your column names. If you only want to use T-SQL than you will have to do something like this:

CASE
           WHEN CHARINDEX(',', YourColumnName) > 0 THEN LEFT(YourColumnName, CHARINDEX(',', YourColumnName) - 1)
           ELSE YourColumnName
END LastName,
CASE
           WHEN CHARINDEX(',', YourColumnName) > 0 THEN SUBSTRING(YourColumnName, CHARINDEX(',', YourColumnName) + 1, 100)
           ELSE Null
END FirstName,
...
From YourStagingTable
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question