Solved

Excel reading, comma seperation

Posted on 2007-03-26
1
307 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

831 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