Solved

Excel reading, comma seperation

Posted on 2007-03-26
1
305 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
1 Comment
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

777 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