Solved

Excel reading, comma seperation

Posted on 2007-03-26
1
303 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
Comment Utility
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.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now